System.String—Find string length
| C# Code Snippets |
| See also |
| edit |
This C# code snippet gets the length of a string.
string motto = "Drive thy business or it will drive thee."; Console.WriteLine ("motto is " + motto.Length + " characters long.");
If the string is uninitialized or null, a NullReferenceException will be generated.
If the string is Empty or equals "", the Length will be zero.