String Interning : String Compare : String C# Examples


C# Examples » String » String Compare »

 

String Interning









    
using  System;

class  MainClass
{
        public  static  void  Main()
        {
                string  s1  =  "Hello";
                string  s2  =  "Hello";
                string  s3  =  "Hello".Substring(0,  4)  +  "o";
                
                Console.WriteLine("Str  ==  :  {0}",  s1  ==  s2);
                Console.WriteLine("Ref  ==  :  {0}",  (object)  s1  ==  (object)  s2);
                
                Console.WriteLine("Str  ==  :  {0}",  s1  ==  s3);
                Console.WriteLine("Ref  ==  :  {0}",  (object)  s1  ==  (object)  s3);
        }
}
    
   
  
   



Output

Str == : True
Ref == : True
Str == : True
Ref == : False


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo String
» String Compare