Do you use String.Empty instead of ""?

Updated by Brook Jeynes [SSW] 1 year ago. See history

123

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.

acknowledgements
related rules