Sunday, July 22, 2007

String: Keyword Basics

• string is an alias for String in the .net framework
• Equality operators == and != are used to compare the values of string objects not references
• Use of @ symbol in string handling:
To assign a string that has quotation marks use @:
Like this: @”good morning”
Or: To include slashes: @”C:\temp\bin”;
• Use of equality operators:
string a = “hello”; string b = “h”;
b = b + “ello”;
Console.Writeline(a==b); // output is true
Console.Writeline((object)a == (object)b); // output is false
• First is true as contents of strings are same/equivalent
• Second is false, as a and b do not refer to the same string instance

No comments:

Post a Comment