Howto declar Guid as const?

  • Thread starter Thread starter Brent Horine
  • Start date Start date
B

Brent Horine

Still a newbie to C#. How do I declare a Guid as a constant?
public const Guid GUID_BLUETOOTH_HCI_EVENT = new Guid(0x850302a, 0xb344,
0x4fda, 0x9b, 0xe9, 0x90, 0x57, 0x6b, 0x8d, 0x46, 0xf0);

gives me the following error: "The expression being assigned to
"...GUID_BLUETOOTH_HCI_EVENT" must be constant"

String and array initializers give me trouble also.



So how/can I declare a Guid as a constant in C#?

Thanks,

Brent
 
You should declare it as a static readonly , since it is an object.
Only value types can be declared as conts. Declare it like this:

public static readonly GUID MY_GUI = Guid.NewGuid();
 
Thanks Roy.

Roy Osherove said:
You should declare it as a static readonly , since it is an object.
Only value types can be declared as conts. Declare it like this:

public static readonly GUID MY_GUI = Guid.NewGuid();
---
Regards,

Roy Osherove
www.iserializable.com
 
Back
Top