String is an alias for System.String class and instead of writing System.String one can use String which is a shorthand for System.String class and is defined in the .NET base class library. The size of the String object in memory is 2GB and this is an immutable object, we can not modify the characters in a string once declared, but we can delete it entirely
Syntax:
String variable = "my string";
Example:
C#
using System;
class GFG{
public static void Main()
{
String b = "Welcome to GeeksforGeeks" ;
Console.WriteLine(a);
}
}
|
Output:
Geeks
A string is a sequence of Unicode characters from U+0000 to U+FFFF. Or we can say that a string represents the text. It is a keyword and it is immutable which means we can not modify the characters in a string once declared, but we can delete it entirely. We can create a string variable using the following syntax:
Syntax:
string variable = "my string";
Example:
C#
using System;
class GFG{
public static void Main()
{
string a = "GeeksforGeeks" ;
Console.WriteLine(a);
}
}
|
Output:
GeeksforGeeks
Difference between String and string
String
|
string
|
It is a class used to access string variables and formatting methods. |
It is a keyword used to create a string variable |
We have to import String from the System.String module. |
There is no need to import any module for string |
It is a data type |
It is a keyword |
It contains different types of methods, properties, etc. |
It is just an alias of the System.String |