2

hi i have found Uri as immutable reference i dont know what it is the exact meaning of immutable reference... can anyone help me?

satheesh.droid
  • 29,947
  • 10
  • 34
  • 34

5 Answers5

5

It's a variable that cannot be changed once set. Very useful when you have multithreaded code since being able to change a variable's value might be a source of many hard to find problems in your code.

If it's immutable, it's usually good.

darioo
  • 46,442
  • 10
  • 75
  • 103
2

A good example of an immutable class within the .NET Framework is System.String. Once you create a String object, you can’t ever change it. There’s no way around it; that’s the way the class is designed. You can create copies, and those copies can be modified forms of the original, but you simply cannot change the original instance for as long as it lives, without resorting to unsafe code. If you understand that, you’re probably starting to get the gist of where I’m going here: For a referencebased object to be passed into a method, such that the client can be guaranteed that it won’t change during the method call, it must itself be immutable.

In a world such as the CLR where objects are held by reference by default, this notion of immutability becomes very important. Let’s suppose that System.String was mutable, and let’s suppose you could write a method such as the following fictitious method:

public void PrintString( string theString )
{
   // Assuming following line does not create a new
   // instance of String but modifies theString
   theString += ": there, I printed it!";
   Console.WriteLine( theString );
}

Imagine the callers’ dismay when they get further along in the code that called this method and now their string has this extra stuff appended onto the end of it. That’s what could happen if System. String were mutable. You can see that String’s immutability exists for a reason, and maybe you should consider adding the same capability to your design.

Scott
  • 13,735
  • 20
  • 94
  • 152
2

EX: string is immutable...
if u have for ex string s =" whatever"
and u output it with uppercase letter..
for ex Console.Write(s.ToUpper())
the console will print u WHATEVER...but the string s will still be whatever... unlike the mutable type which will change the string from whatever to WHATEVER

Grace
  • 1,265
  • 21
  • 47
0

In java , every thing is treated as String and object , Now try to think that if have created a program of 10000 lines and in this there you have added "public" 100 times so do you think that every time this public is created in storage . else what we can do , we can created something like that when ever we find something like this we will fetch it from there there ( String pool )

Tushar
  • 95
  • 1
  • 5
0

"immutable" means "can't change the value"

"mutable" == "changeable"

"immutable" == "not changeable"

duffymo
  • 305,152
  • 44
  • 369
  • 561