Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare a constant Guid in C#?

Is it possible to declare a constant Guid in C#?

I understand that I can declare a static readonly Guid, but is there a syntax that allows me to write const Guid?

like image 888
smartcaveman Avatar asked Feb 07 '11 21:02

smartcaveman


3 Answers

No. The const modifier only applies to "primitive" types (bool, int, float, double, long, decimal, short, byte) and strings. Basically anything you can declare as a literal.

like image 106
Quick Joe Smith Avatar answered Nov 14 '22 02:11

Quick Joe Smith


Declare it as static readonly Guid rather than const Guid

like image 50
Jaime Botero Avatar answered Nov 14 '22 03:11

Jaime Botero


public static readonly Guid Users = new Guid("5C60F693-BEF5-E011-A485-80EE7300C695");

and that's that.

like image 37
Stefan Avatar answered Nov 14 '22 03:11

Stefan