Advertuse

Search This Blog

Your Ad Here

Friday 8 May, 2009

immutable types in C# (અવિકારી ટાઇપ in C#)

string s1 = "hello";
string s2 = s1;
Then s2 does at this point reference the same string object as s1. However, when the value of s1 is changed, for instance with

(અહી s2 વેરિએબલ અને s1 વેરિએબલ એક મેમરી એડ્રેસ ને રીફેર કરશે હવે ધારોકે s1 વેરિએબલ ચેન્જ કરવામાં આવે તો )

s1 = "goodbye";
what happens is that a new string object is created for s1 to point to. Hence, following this piece of code, s1 equals "goodbye", whereas s2 still equals "hello".

( એક નવો સ્ટ્રીંગ object મેમરી માં બને જેમાં " goodbye " સ્ટોર કર્યું હોય અને s1 વેરિએબલ તે ને રેફેર કરે જેથી કરીને ને s1 =" goodbye " થાય પણ, s2 હજી પણ " hello " ને રીફેર કરશે)

Basically, an object is immutable if its state doesn’t change once the object has been created. Consequently, a class is immutable if its instances are immutable.

(આવું થવાનું કારણ છે કે સ્ટ્રીંગ અવિકારી ટાઇપ છે . માટે અવિકારી ટાઇપ ને વ્યાખ્યા નીચે મુજબ થાય

"જે OBJECT એક વાર મેમરી માં ક્રીઅટે કરાયા પછી તેનું STATE બદલી શકાતું નથી તેને અવિકારી ટાઇપ કહે છે .")