Empty String
In this chapter you will learn:
Empty string vs null string
string
is a reference type therefore we can assign null
to string
variable.
using System;//from j a v a2s . c o m
class Sample
{
public static void Main()
{
string s = null;
}
}
Empty string
is a string
with no characters.
The length of an empty string
is 0.
Empty string
is not null
string
.
using System;//from j a v a 2 s.c o m
class Sample
{
public static void Main()
{
string s = "";
Console.WriteLine(s.Length);
}
}
The output:
String length for empty string
From the code above we can see that the length of a empty string
is 0.
We cannot check the Length
property on an empty string
.
using System;// ja v a 2s . co m
class Sample
{
public static void Main()
{
string s = null;
Console.WriteLine(s.Length);
}
}
The output:
Next chapter...
What you will learn in the next chapter:
- Compare two DateTimeOffset values for equality
- How to use EqualsExact method to compare DateTimeOffset
- Compare method
Home » C# Tutorial » String