473,386 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to declare const Guid ?

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
4 13832
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Dylan Nicholson | last post by:
Is there any way of declaring the parameter "array" below to be const, so that the function as written will not compile: void foo(int array /*const*/) { array = array; // should not be allowed...
5
by: Ingo Brueckl | last post by:
I need to declare a fixed array of (already defined and working) sort functions (sortfunc1, sortfunc2, sortfunc3) to pass one element of the array to qsort itself: int index; ??? func =...
3
by: classicist | last post by:
Suppose I have a function which takes an argv-style pseudo-matrix and modifies neither the strings nor the pointers. How do I use the const qualifier to signal my intentions w/o drawing compiler...
1
by: notregister | last post by:
Hi i looking for example of declaring and use of GUID, the msdn example is very confusing, can anyone help me? if my GUID is F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4, how do i store it in a...
23
by: mark.moore | last post by:
I know this has been asked before, but I just can't find the answer in the sea of hits... How do you forward declare a class that is *not* paramaterized, but is based on a template class? ...
5
by: iwdu15 | last post by:
hi, i need to have a declare statement for an API to call a method in it, the only problem is that i dont neccessarily know where on the comp it will be. I kno it will be in my application folder,...
1
by: Jeff Johnson | last post by:
I want to do this in my Web service: public static Guid ApplicationId { get { return _appId; } } And then in my external code do this: Guid webServiceGuid =...
3
by: johnmmcparland | last post by:
Hi all, I would like to have a static constant array inside a class definition which would contain the number of days in each month (I am writing a Date class as an exercise). However my...
1
by: peary | last post by:
Hi, everyone, I'm writing a program to discover wireless network using Windows Native Wifi API & VB.net. I have to declare the windows API in my VB.net program. The original windows...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.