Howto declar Guid as const?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brent Horine

    Howto declar Guid as const?

    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_BLUETO OTH_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


  • Roy Osherove

    #2
    Re: Howto declar Guid as const?

    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


    On Thu, 6 Nov 2003 09:38:41 -0500, "Brent Horine"
    <bhorine@NOSPAM MINGPLEASEclarc ona.com> wrote:
    [color=blue]
    >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_BLUET OOTH_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
    >[/color]

    Comment

    • Brent Horine

      #3
      Re: Howto declar Guid as const?

      Thanks Roy.

      "Roy Osherove" <royo@iserializ able.com> wrote in message
      news:oonkqv40m7 v8l8li8jvelii2u 8o3sdab0o@4ax.c om...[color=blue]
      > 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
      >
      > On Thu, 6 Nov 2003 09:38:41 -0500, "Brent Horine"
      > <bhorine@NOSPAM MINGPLEASEclarc ona.com> wrote:
      >[color=green]
      > >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_BLUET OOTH_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
      > >[/color]
      >[/color]


      Comment

      Working...