i have a small confusion that when we compare like == or equal function then both does the same job. u have a very basic question here.
- int x = 1000;
- int y = 1000;
- if (x == y)
- Console.WriteLine("Value is same");
- else
- Console.WriteLine("Value is not same");
- if (x.Equals(y))
- Console.WriteLine("Value is same");
- else
- Console.WriteLine("Value is not same");
- if (object.ReferenceEquals(x,y))
- Console.WriteLine("ref is same");
- else
- Console.WriteLine("ref is not same");
- string s1 = "Hello";
- string s2 = "Hello";
- if (s1 == s2)
- Console.WriteLine("Value is same");
- else
- Console.WriteLine("Value is not same");
- if (s1.Equals(s2))
- Console.WriteLine("Value is same");
- else
- Console.WriteLine("Value is not same");
- if (object.ReferenceEquals(s1, s2))
- Console.WriteLine("ref is same");
- else
- Console.WriteLine("ref is not same");
i know that this kind of checking if (x == y) is based on value but when i use Equals function then i saw Equals is also work like == operator....am i right ?
how to check the reference ?
- if (object.ReferenceEquals(x,y))
- Console.WriteLine("ref is same");
- else
- Console.WriteLine("ref is not same");
see more for string reference check
- if (object.ReferenceEquals(s1, s2))
- Console.WriteLine("ref is same");
- else
- Console.WriteLine("ref is not same");
i like to know what are the best process to know value and reference is same or not whatever data type we use may be string or integer or float etc. please some one help me to understand this.
one guy said string in dotnet is interned. what is the meaning of In .NET strings are interned ? interned or internal is same ?
thanks
Dharmraj ThakurPosted May 9, 2017, 6:16 AM
Posted May 9, 2017, 7:24 AM
Posted May 9, 2017, 6:06 AM
Dharmraj ThakurPosted May 9, 2017, 4:47 AM