Jagged Arrays ,StringBuilder” and “String” in C#.
An array is collection of similar data type. The array which has elements of type array is called jagged array. The elements can be of different dimensions and sizes. We can also call jagged array as Array of arrays.
StringBuilder is mutable, which means once object for stringbuilder is created, it later be modified either using Append, Remove or Replace.
String is immutable and it means we cannot modify the string object and will always create new object in memory of string type.
Both String and StringBuilder have Unicode characters of type Char and support an indexer that returns Char. Because the String class is immutable, its indexer is read-only, but the StringBuilder indexer is readable/writeable.
Example:
using System;
using System.Linq;
using System.Text;
class Program
{
static void Main(string[] args)
{
//Below are the example of string and stringbuilder
string newstr = "Wellcome";
//Creates a new object when we concatenate any other words along
//with str variable it does not actually modify the str variable, instead it creates a whole new string in this example..
newstr = newstr + " to sring developeraspdeveloper";
Console.WriteLine(newstr);
StringBuilder s = new StringBuilder("This is string builder");
s.Append(" To developeraspdeveloper");
Console.WriteLine(s);
Console.Read();
}
}
String is immutable and it means we cannot modify the string object and will always create new object in memory of string type.
Both String and StringBuilder have Unicode characters of type Char and support an indexer that returns Char. Because the String class is immutable, its indexer is read-only, but the StringBuilder indexer is readable/writeable.
Example:
using System;
using System.Linq;
using System.Text;
class Program
{
static void Main(string[] args)
{
//Below are the example of string and stringbuilder
string newstr = "Wellcome";
//Creates a new object when we concatenate any other words along
//with str variable it does not actually modify the str variable, instead it creates a whole new string in this example..
newstr = newstr + " to sring developeraspdeveloper";
Console.WriteLine(newstr);
StringBuilder s = new StringBuilder("This is string builder");
s.Append(" To developeraspdeveloper");
Console.WriteLine(s);
Console.Read();
}
}

0 Comments