C#C
C#4y ago
Gladiator

❔ static fields for struct types

(1)
public static class StructA  
{
   public static readonly StructA  ValueA = new (..) ;
}

or as Utility class
public static class Utility
{
   public static readonly StructA  ValueA = new (..) ;
}

(2)
public static class Utility
{
   private static readonly StructA  _valueA = new (..) ;
   public static StructA ValueA => _valueA;
}

The first and second one are the same but I have seen some libs prefer to implement them like (2)
(3)
public static class Utility
{
   // Initialize every time.
   public static StructA ValueA => new(..);
}

and what is the benefit of implementation (3)
Was this page helpful?