Hi programmers , welcome to new article of ozanecare. this article i am going to explain the string pool in c# programming language. The String Pool : If multiple string literal or string object hold the same string values. CLR will allocate a single memory location. see below image.
the above image explain the process happening in heap memory String st1 = “Program” and String st2 =”Program”.
the value of st1 and st2 are same so CLR will allocate a single memory location. String str1 = new String(“Program”) and String str2 = new String(“Program”). the value of str1 and str2 objects are same so it generate same memory for these two objects. if you take st3 it’ll generate different memory.
Example of String pool in c#. st1 and st2 has same value so heap memory generated same but different memory for st3. str1 and str2 has same value so heap memory generated same. see below image.
Happy Coding Thanks…