find the length of a string in csharp

To find the length of a string in C#, you can use the .Length property of the string object. Here is an example that demonstrates how to find the length of a string in C#:

main.cs
string myString = "Hello, world!";
int stringLength = myString.Length;
Console.WriteLine("The length of the string is: " + stringLength);
138 chars
4 lines

In this example, the myString.Length property returns an integer that represents the number of characters in the myString string. This integer value is then stored in the stringLength variable, which is printed to the console using the Console.WriteLine() method.

related categories

gistlibby LogSnag