?

Log in

No account? Create an account

Previous Entry | Next Entry

string str = ".NET interview questions"; // Instance 1
string str1 = ".NET  interview questions"; // points to same Instance 1   


No, the above code will not create multiple instances but rather they will point to the same memory instance. If the compiler finds the same value in memory he points the variable to the same instance rather than creating a new one.


The below two code snippets will create multiple memory instances of the variable.

string str = ".NET interview questions"; // Instance 1
string str1 = ".NET  interview questions"; // points to different instances.

string str = ".NET interview questions"; // Instance 1
string str1 = "c# interview questions"; // points to different instances


You can check if they point to the same memory instance or multiple instances by using “ReferenceEqual” which belongs to “object” type. It returns true if the objects point to the same instance.

object.ReferenceEquals(str, str1);


You can also visit our site for more .NET interview question with answers at www.questpond.com

 You can also see this link c# interview question video: - What kind of questions are asked in .NET interviews?


Copy right www.questpond.com

Tags

Latest Month

September 2017
S M T W T F S
     12
3456789
10111213141516
17181920212223
24252627282930
Powered by LiveJournal.com