Howto declar Guid as const?

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
 
R

Roy Osherove

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();
 
B

Brent Horine

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top