Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

Why strings are immutable in .NET?

$
0
0

Hi all,

what does type String is immutable mean?

I did an assignment on that:

string s;

s = "car";
s += "bus"....

And then,

StringBuilder sb = new StringBuilder(10);

sb.Append("car")
sb.Append("bus")

But both give the same result.

It is said that StringBuilder is there to create dynamic strings.
But I feel like we can use string to do the same thing with out any issue.

  • Can anyone give me a good example to differentiate between string and stringbuilder?
  • What is the difference between String and StringBuilder?
  • Why Strings are immutable?
  • Why we use new key word only to declare StringBuilder and not with string declaration?

Please help me to resolve this.

Thanks and Regards,
Jay.


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>