By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,563 Members | 1,735 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,563 IT Pros & Developers. It's quick & easy.

How to declare const Guid ?

P: n/a
I need to replace string with Guid ready to use:

public const string GUID_1 = "CF0003D61F6E4D6AA6B17B18E5057FCD";

like

public const Guid ...

Is there any chance to do this.

pawelf

Nov 15 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi Pawelf,

Can't be done. I suggest either keeping it as a string and converting it to a Guid value as necessary or making it a static readonly field:

public static readonly Guid GUID_1 = new Guid("CF0003D61F6E4D6AA6B17B18E5057FCD");

Regards,
Dan
"PawelF" <fa****@visionsoft.com.pl> wrote in message news:e9**************@TK2MSFTNGP12.phx.gbl...
I need to replace string with Guid ready to use:

public const string GUID_1 = "CF0003D61F6E4D6AA6B17B18E5057FCD";

like

public const Guid ...

Is there any chance to do this.

pawelf

Nov 15 '05 #2

P: n/a
According to the online documentation:

The keyword const is used to modify a declaration of a field or local variable. It specifies that the value of the field or the local variable cannot be modified. A constant declaration introduces one or more constants of a given type. The declaration takes the form:

[attributes] [modifiers] const type declarators;where:

attributes (optional)
Optional declarative information. For more information on attributes and attribute classes, see C# Attributes.
modifiers (optional)
Optional modifiers that include the new modifier and one of the four access modifiers.
type
One of the types: byte, char, short, int, long, float, double, decimal, bool, string, an enum type, or a reference type.
So, as far as I understand, there is no way to do that because Guid is not listed in the types allowed for the const keyword.

But you can get away with something like:

const string strGuid = "CF0003D6-1F6E-4D6A-A6B1-7B18E5057FCD";
Guid gd = new Guid (strGuid);

and use the strGuid where you need.

--
Cezary Nolewajka
mailto:c.*********************@no-sp-am-eh-mail.com
remove all "no-sp-am-eh"s to reply

"PawelF" <fa****@visionsoft.com.pl> wrote in message news:e9**************@TK2MSFTNGP12.phx.gbl...
I need to replace string with Guid ready to use:

public const string GUID_1 = "CF0003D61F6E4D6AA6B17B18E5057FCD";

like

public const Guid ...

Is there any chance to do this.

pawelf

Nov 15 '05 #3

P: n/a
public const Guid MyGuid = new Guid("CF0003D61F6E4D6AA6B17B18E5057FCD");

that should work.

--- Nick
"PawelF" <fa****@visionsoft.com.pl> wrote in message
news:e9**************@TK2MSFTNGP12.phx.gbl...
I need to replace string with Guid ready to use:
public const string GUID_1 = "CF0003D61F6E4D6AA6B17B18E5057FCD";
like
public const Guid ...
Is there any chance to do this.
pawelf
Nov 15 '05 #4

P: n/a
you can return a guid as a read only property

private Guid _myGuid = new Guid("CF0003D61F6E4D6AA6B17B18E5057FCD");
public Guid MyGuid
{
get { return _myGuid; }
}

HTH,
--- Nick
"PawelF" <fa****@visionsoft.com.pl> wrote in message
news:e9**************@TK2MSFTNGP12.phx.gbl...
I need to replace string with Guid ready to use:
public const string GUID_1 = "CF0003D61F6E4D6AA6B17B18E5057FCD";
like
public const Guid ...
Is there any chance to do this.
pawelf
Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.