Friday, April 9, 2010
String objects are immutable as its state cannot be modified once created.
Every time when we perform any operation like copy, replace, case conversion or when we pass a string object as a parameter to a method a new object will be created.
String s = "ABC";
Here Replace() method will not change data that s contains, instead a new string object is created to hold data "XBC" and the reference to this object is returned by Replace() method.
So in order to point s to this object we need to write below line.
s = s.Replace("A","X");
Also Read other Top Articles
- JSON Serialization in VS 2008
- Implementing Forms Authentication in Silverlight Application.
- Making GridView Rows or Individual Cells Clickable and Selectable.
- Enabling browser back button for GridView Paging and Sorting in Ajax 1.1 and 3.5 (using Visual Studio 2005/ Visual studio 2008)
- How to pass values from User Control to Page or calling Page methods from User Control.
- What is WCF?
- New features in C# 4.0
- C# to VB.NET and VB.NET to C# online free converter tools.