Do you use String.Empty instead of ""?

Loading last updated info...

Since .NET 5+, the choice between using String.Empty and "" is a stylistic decision for the team. In .NET Framework, "" is less efficient than String.Empty from a memory perspective which can result in better performance due to faster garbage collection.

From the team that worked on performance in .NET: String.Empty vs "" in modern .NET language

public string myString
{
get
{
return ;
}
}

❌ Figure: Figure: Bad code if used in .NET Framework. Low performance

public string myString
{
get
{
return string.Empty;
}
}

✅ Figure: Figure: Good code if used in .NET Framework. Higher performance

We have a program called SSW Code Auditor to check for this rule.

Categories

Authors

Need help?

SSW Consulting has over 30 years of experience developing awesome software solutions.

We open source.Loving SSW Rules? Star us on GitHub. Star