© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
6 replies
Gladiator

❔ static fields for struct types

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

or as Utility class
public static class Utility
{
   public static readonly StructA  ValueA = new (..) ;
}
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;
}
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(..);
}
public static class Utility
{
   // Initialize every time.
   public static StructA ValueA => new(..);
}

and what is the benefit of implementation (3)
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Struct Fields
C#CC# / help
4y ago
Fields marked as 'static'
C#CC# / help
3mo ago
✅ Does C# have anonymous struct initializers for class fields?
C#CC# / help
9mo ago
❔ Consider struct or class types for small event args
C#CC# / help
4y ago