Click here to Skip to main content
15,889,281 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# Network and streams Pin
Gerry Schmitz10-May-17 5:00
mveGerry Schmitz10-May-17 5:00 
GeneralRe: C# Network and streams Pin
TheTrigger10-May-17 5:56
TheTrigger10-May-17 5:56 
GeneralRe: C# Network and streams Pin
Dave Kreskowiak10-May-17 6:25
mveDave Kreskowiak10-May-17 6:25 
GeneralRe: C# Network and streams Pin
TheTrigger10-May-17 8:50
TheTrigger10-May-17 8:50 
QuestionLabel link on top of the page Pin
Member 131892689-May-17 3:51
Member 131892689-May-17 3:51 
AnswerRe: Label link on top of the page Pin
Richard MacCutchan9-May-17 4:51
mveRichard MacCutchan9-May-17 4:51 
AnswerRe: Label link on top of the page Pin
OriginalGriff9-May-17 5:36
mveOriginalGriff9-May-17 5:36 
QuestionC#: How to compare variables by value and reference type Pin
Tridip Bhattacharjee8-May-17 22:24
professionalTridip Bhattacharjee8-May-17 22:24 
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.

see my program full code
C#
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 ?
C#
if (object.ReferenceEquals(x,y))
    Console.WriteLine("ref is same");
else
    Console.WriteLine("ref is not same");



i saw in this case else portion execute........why because different memory is allocated for x and y ?
see more for string reference check
C#
if (object.ReferenceEquals(s1, s2))
        Console.WriteLine("ref is same");
    else
        Console.WriteLine("ref is not same");



in this scenario s1 and s2 ref found same which is not clear to me because s1 and s2 ref should be different because two are different variable so how s1 and s2 reference check become 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 ?

please discuss with a example just to clarify the meaning of string is interned in dotnet.

thanks
tbhattacharjee

AnswerHelp vampire Pin
Pete O'Hanlon8-May-17 23:05
mvePete O'Hanlon8-May-17 23:05 
GeneralRe: Help vampire Pin
OriginalGriff9-May-17 0:51
mveOriginalGriff9-May-17 0:51 
GeneralRe: Help vampire Pin
Gerry Schmitz9-May-17 6:15
mveGerry Schmitz9-May-17 6:15 
AnswerRe: C#: How to compare variables by value and reference type Pin
Richard MacCutchan8-May-17 23:25
mveRichard MacCutchan8-May-17 23:25 
AnswerMessage Closed Pin
8-May-17 23:27
harold aptroot8-May-17 23:27 
QuestionRedundent code in a class Pin
hussain.rao158-May-17 20:29
hussain.rao158-May-17 20:29 
AnswerRe: Redundent code in a class Pin
Richard MacCutchan8-May-17 21:06
mveRichard MacCutchan8-May-17 21:06 
GeneralRe: Redundent code in a class Pin
hussain.rao1511-May-17 23:56
hussain.rao1511-May-17 23:56 
GeneralRe: Redundent code in a class Pin
Richard MacCutchan12-May-17 0:24
mveRichard MacCutchan12-May-17 0:24 
AnswerRe: Redundent code in a class Pin
Gerry Schmitz9-May-17 6:17
mveGerry Schmitz9-May-17 6:17 
QuestionCan you speed up the calculation of programs using software methods and how much? Pin
Member 127091098-May-17 1:21
Member 127091098-May-17 1:21 
QuestionQuestiongame over the net - client crash Pin
Member 129316127-May-17 7:52
Member 129316127-May-17 7:52 
AnswerRe: Questiongame over the net - client crash Pin
Richard Andrew x647-May-17 11:32
professionalRichard Andrew x647-May-17 11:32 
AnswerRe: Questiongame over the net - client crash Pin
OriginalGriff7-May-17 21:41
mveOriginalGriff7-May-17 21:41 
QuestionCreate Dynamic buttons Pin
Member 131834647-May-17 0:31
Member 131834647-May-17 0:31 
QuestionRe: Create Dynamic buttons Pin
CHill607-May-17 0:33
mveCHill607-May-17 0:33 
AnswerRe: Create Dynamic buttons Pin
User 41802547-May-17 8:49
User 41802547-May-17 8:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.