mark007 Posted August 1, 2005 Posted August 1, 2005 Trying to understand some C# code on the net: if ((string1 = string2) != null) { } What is this saying? Translators recommend: if not (string1=string2) is nothing then end if Which is incorrect as string1=string2 is boolean. I therefore thought it might be: if string1<>string2 then but it seems to be doing more than this. Any ideas? :) Quote Please check the Knowledge Base before you post. "Computers are useless. They can only give you answers." - Pablo Picasso The Code Net
ALEX_0077 Posted August 1, 2005 Posted August 1, 2005 If (Not (string1 = string2)) Then 'some code here... End If Trying to understand some C# code on the net: if ((string1 = string2) != null) { } What is this saying? Translators recommend: if not (string1=string2) is nothing then end if Which is incorrect as string1=string2 is boolean. I therefore thought it might be: if string1<>string2 then but it seems to be doing more than this. Any ideas? :) Quote Me = 49% Linux, 49% Windows, 2% Hot gas. ...Bite me. My Site: www.RedPierSystems.net -.net, php, AutoCAD VBA, Graphics Design
mark007 Posted August 1, 2005 Author Posted August 1, 2005 What the difference between this: If (Not (string1 = string2)) Then 'some code here... End If and If (string1 <> string2) Then 'some code here... End If ? Quote Please check the Knowledge Base before you post. "Computers are useless. They can only give you answers." - Pablo Picasso The Code Net
ALEX_0077 Posted August 1, 2005 Posted August 1, 2005 absolutly nothing. The <> method is just less code. What the difference between this: If (Not (string1 = string2)) Then 'some code here... End If and If (string1 <> string2) Then 'some code here... End If ? Quote Me = 49% Linux, 49% Windows, 2% Hot gas. ...Bite me. My Site: www.RedPierSystems.net -.net, php, AutoCAD VBA, Graphics Design
IngisKahn Posted August 1, 2005 Posted August 1, 2005 The correct translation of if ((string1 = string2) != null) { //.... } is: string1 = string2 If Not string1 Is Nothing Then '... End If Quote "Who is John Galt?"
mark007 Posted August 1, 2005 Author Posted August 1, 2005 In that case I've tried that and it isn't the exact translation. Any more ideas? Quote Please check the Knowledge Base before you post. "Computers are useless. They can only give you answers." - Pablo Picasso The Code Net
mark007 Posted August 1, 2005 Author Posted August 1, 2005 Ah, thanks IgisKhan, I shall try that! :) Quote Please check the Knowledge Base before you post. "Computers are useless. They can only give you answers." - Pablo Picasso The Code Net
mark007 Posted August 1, 2005 Author Posted August 1, 2005 I guess C# is similar to PHP in that it has == for comparison and = for assignment. Should have realised. Thanks alot though. :) Quote Please check the Knowledge Base before you post. "Computers are useless. They can only give you answers." - Pablo Picasso The Code Net
ALEX_0077 Posted August 1, 2005 Posted August 1, 2005 The correct translation of if ((string1 = string2) != null) { //.... } is: string1 = string2 If Not string1 Is Nothing Then '... End If Thats right. = is not the same as == (duh! ) :D Quote Me = 49% Linux, 49% Windows, 2% Hot gas. ...Bite me. My Site: www.RedPierSystems.net -.net, php, AutoCAD VBA, Graphics Design
Joe Mamma Posted August 1, 2005 Posted August 1, 2005 Which is incorrect as string1=string2 is boolean.one of the many inadequacies of VB.NOT (context sensitive operators). . . In c#, the assignment falls through so you can initialize things like: string s, s1; string s2 = s1 = s = "foobar"; int i, i1; int i2 = i1 = i = 1; MyObject mo, mo1; MyObject mo2 = mo1 = mo = new MyObject(); with those statements: s, s1, and s2 all contain "Foobar". . . i, i1, and i2 all contain 1. . . and mo, mo1 and mo2 all contain a reference to the same instance of a MyObject. that being said. . . if ((string1 = string2) != null) { //.... } reads: If, after assigning string2 to string1, the value assigned to string1 is not null then. . . in vb it would be: string1 = string2 if ( not (string1 is nothing) ) then end if. . . Also keep in mind - dim mystring as String = nothing dim test as bool = mystring = string.Empty The value of test is false. Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.