System.String—Find string length
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
| 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.