How to check if string reference is equal in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string s1 = "c#";
            string s2 = "c#";
            Console.WriteLine(string.ReferenceEquals(s1, s2));

            s1 = "c++";
            Console.WriteLine(string.ReferenceEquals(s1, s2));
            Console.WriteLine(s2);

            string s3 = "java";
            string s4 = "javax";
            Console.WriteLine(string.ReferenceEquals(s3, s4));
        }
    }
}


/*
run:
 
True
False
c#
False

*/

 



answered Jan 2, 2017 by avibootz
...