In C#, a string is a sequence of Unicode characters.
You can create a string in C# by enclosing a sequence of characters in double quotes:
string message = "Hello, World!";You can also create a string using the string keyword and the new operator:
string message = new string('a', 5); // creates a string of 5 'a'sYou can concatenate strings using the + operator:
string greeting = "Hello, ";
string name = "Alice";
string message = greeting + name; // message is "Hello, Alice"You can also use the string.Format() method to create a formatted string:
string message = string.Format("Hello, {0}! You are {1} years old.", name, age);There are many other string methods and properties available in C# that you can use to manipulate and work with strings.
For example, you can use the
string.Length property to get the length of a string, the
string.Substring() method to extract a sub-string from a string, and the
string.Replace() method to replace all occurrences of a specified string with another string.
You can find more information about strings in C# in the official documentation: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/string
Comments
Post a Comment