Monday, 4 September 2017

String Pool in C#

The string pool is a table that contains a single reference to each unique literal string declared in your application which use by the Common Language Runtime (CLR) to minimize string storage requirements.



string string1 = "xyz";
string string2 = "xyz";


According to above code string1 and string2 assign to same literal string (“xyz”). The string pool contains a single reference for these unique literal strings.

To confirm if the same reference has been assigned we can check for the HashCode for both the string object.
Code and Output as Follow.


Console.WriteLine("Hash Code of string1- " + string1.GetHashCode());
Console.WriteLine("Hash Code of string2- " + string2.GetHashCode());

1 comment:

  1. How to win at the best casino bonuses - Casino Roll
    How 솔레어 to Win at 벳 삼육오 the Best Casino Bonuses — As you 업소 추천 can see, these casino promotions allow you 온카판 to win money or prizes without even having to 텍사스 홀덤 risk your

    ReplyDelete

Single Responsibility Principle (SRP)