‘inetreStrings’ – liked the nomenclature and the sense of humor of the author of it very much.

String vs string
Lower case string is simply an alias for System.String in the .NET Framework.
== or .Equals
A rule of thumb is that for almost all reference types e.g. objects, use Equals when you want to test equality. == compares whether two references (i.e. object instances) refer to the same object.
Primitive types can be compared for equality using ==, but in the case of strings, the variables on each side of the operators must be of type string.
Have a look at the following code and output, taken from Jon Skeet’s blog.

01    using  System;
03    public class Test
04    {
05    static void Main()
06    {
07    // Create two equal but distinct strings
08    string a = new string(new char[] {'h', 'e', 'l', 'l', 'o'});
09    string b = new string(new char[] {'h', 'e', 'l', 'l', 'o'});
11    Console.WriteLine (a==b);
12    Console.WriteLine (a.Equals(b));
14    // Now let's see what happens with the same tests but
15    // with variables of type object
16    object c = a;
17    object d = b;
19    Console.WriteLine (c==d);
20    Console.WriteLine (c.Equals(d));
21    }
22    }
23    The results are:
25    True
26    True
27    False
28    True

@ before a string
Using @ before a string means the escape sequences are not processed. This making it easier to write fully qualified path names for example.
@”c:DocsSourcea.txt” // rather than “c:\Docs\Source\a.txt”
String objects are immutable, and so editing them, using Replace for example, results in a entirely new string being created, with new memory allocation. The original string is left intact in memory.
The StringBuilder class is designed for situations when one needs to work with a single string and make an arbitrary number of iterative changes to it. New memory allocation is not needed.

Came across the above on Bishop’s Blog while searching about something related to VSTO.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s