Strings are used for storing text.
A string
variable contains a collection of characters surrounded by double quotes:
Create a variable of type string
and assign it a value:
string greeting = "Hello";
A string variable can contain many words, if you want:
A string in C# is actually an object, which contain properties and methods that can perform certain operations on strings. For example, the length of a string can be found with the Length
property:
string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
Console.WriteLine("The length of the txt string is: " + txt.Length);
There are many string methods available, for example ToUpper()
and ToLower()
, which returns a copy of the string converted to uppercase or lowercase:
string txt = "Hello World";
Console.WriteLine(txt.ToUpper()); // Outputs "HELLO WORLD"
Console.WriteLine(txt.ToLower()); // Outputs "hello world"
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!