To check if the length of a string is greater than zero in C#, you can use the Length
property of the string
class and an if
statement.
main.cs113 chars6 lines
Alternatively, you can use the string.IsNullOrEmpty()
method to check if a string is either null or an empty string:
main.cs133 chars6 lines
Note that if you attempt to call the Length
property on a null string, you will get a NullReferenceException
. Therefore, it's good practice to use the string.IsNullOrEmpty()
method if you're unsure whether a string may be null or empty.
gistlibby LogSnag