SSW Foursquare

Do you use String.Empty instead of ""?

Last updated by Brook Jeynes [SSW] 8 months ago.See history

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: Bad code if used in .NET Framework. Low performance

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

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

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

We open source. Powered by GitHub