What is a mutable type?

  • Thread starter Thread starter Simon Woods
  • Start date Start date
S

Simon Woods

Hi

I wonder if someone could explain the above to me. The examples I've
seen seem to indicate that it is effectively a read-only class, but I'm
sure that's being over simplistic. But what is the significance of them?

Thanks

Simon
 
mutable: capable or subject to change

I think you are thinking of immutable. Strings are immutable.
 
Forgot about 'what is the signicance'.

Most things are mutable, its the immutable things that have to be handled
differently.

Sub Main()
Dim s1 As String = "123"
Dim s2 As String = s1
Console.WriteLine("{0}", (s1 Is s2))
s1 = s1 & "45"
Console.WriteLine("{0}", (s1 Is s2))
Console.ReadLine()
End Sub
The output is
True
False
So when you attemped to change s1, a brand new string object was created
with value "12345" and s1 points to it.
 
Back
Top