C# static readonly vs constant

Static readonly

  • set at run-time
  • referencing field, not value
  • able to hold reference and value types

Constant

  • set at compile-time
  • referencing value – after change the constant in library or assembly you must recompile all libraries or assemblies which references the constant
  • able to hold only value types plus the special .NET ones string and null
  • can be lazy-loaded
  • can contain calculated values
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s