| |
GeekInterview.com > Interview Questions > Microsoft > Microsoft.NET
| Print | |
Question: What is meant by Mutable and Immutable classes?
|
| July 07, 2008 11:16:30 |
#5 |
| bobby420 |
Member Since: July 2008 Total Comments: 1 |
RE: What is meant by Mutable and Immutable classes? |
Best Example to understand Mutable and Immutable is string. string class is immutable. so if string x = "123"; if you do x = x + "abc" what it does is it assigns new memory location for 123 and abc. Then adds the two strings and places the computed results in new memory location and points x to it.
if you use System.Text.StringBuilder sb = new System.Text.StringBuilder("123"); sb.Append("abc"); x=sb.ToString();
stringbuilder is mutable class. It just adds the string to same memory location. This way string manipulation is faster.
I hope this helps.
|
| |
Back To Question | |