Hi,
I'd like to create a Guid constant and the following doesn't work (Cannot
implicitly convert type 'string' to 'System.Guid') :
public const Guid MyGuid = "{ccae2079-2ebc-4200-879d-866fc82e6afa}";
Ideas?
Thanks,
Erik 7 21800
Should be a constant
public const string MyGuid = "{ccae2079-2ebc-4200-879d-866fc82e6afa}";
or just declare a public variable
public Guid MyGuid = new Guid("{ccae2079-2ebc-4200-879d-866fc82e6afa}");
Gabriel Lozano-Morán
On Mon, 25 Apr 2005 11:38:31 -0500, ESPNSTI wrote: Hi,
I'd like to create a Guid constant and the following doesn't work (Cannot implicitly convert type 'string' to 'System.Guid') :
public const Guid MyGuid = "{ccae2079-2ebc-4200-879d-866fc82e6afa}";
Ideas?
Thanks, Erik
Only value types can be declared as constants. A Guid is not a value type. But
you can declare it as a static readonly.
public static readonly Guid MyGuid = new
Guid("{ccae2079-2ebc-4200-879d-866fc82e6afa}");
hth
--
Claudio Grazioli http://www.grazioli.ch http://www.grazioli.ch/HommingbergerGepardenforelle/
Thanks.
Well, that kinda bites :(.
I was hoping to use it in a custom attribute (which doesn't like the public
static readonly), I'll just have to use the Guids in string format.
> Only value types can be declared as constants. A Guid is not a value type. But you can declare it as a static readonly.
And also two reference types the null type and string
Gabriel Lozano-Morán
One correction: you state that a Guid is not a value type, which is wrong. A
Guid is in fact a value type.
"Claudio Grazioli" <ne********@gmx-ist-cool.de> wrote in message
news:dg*****************************@40tude.net... On Mon, 25 Apr 2005 11:38:31 -0500, ESPNSTI wrote:
Hi,
I'd like to create a Guid constant and the following doesn't work (Cannot implicitly convert type 'string' to 'System.Guid') :
public const Guid MyGuid = "{ccae2079-2ebc-4200-879d-866fc82e6afa}";
Ideas?
Thanks, Erik
Only value types can be declared as constants. A Guid is not a value type. But you can declare it as a static readonly.
public static readonly Guid MyGuid = new Guid("{ccae2079-2ebc-4200-879d-866fc82e6afa}");
hth -- Claudio Grazioli http://www.grazioli.ch http://www.grazioli.ch/HommingbergerGepardenforelle/
Guid *is* a value type; from .NET SDK:
[Serializable]
public struct Guid : IFormattable, IComparable
I think you mean only build-in types can be const. The SDK states only these
types can be const:
byte, char, short, int, long, float, double, decimal, bool, string
KH
"Claudio Grazioli" wrote: On Mon, 25 Apr 2005 11:38:31 -0500, ESPNSTI wrote:
Hi,
I'd like to create a Guid constant and the following doesn't work (Cannot implicitly convert type 'string' to 'System.Guid') :
public const Guid MyGuid = "{ccae2079-2ebc-4200-879d-866fc82e6afa}";
Ideas?
Thanks, Erik
Only value types can be declared as constants. A Guid is not a value type. But you can declare it as a static readonly.
public static readonly Guid MyGuid = new Guid("{ccae2079-2ebc-4200-879d-866fc82e6afa}");
hth -- Claudio Grazioli http://www.grazioli.ch http://www.grazioli.ch/HommingbergerGepardenforelle/
On 2005-04-25, ESPNSTI <ES*********@Hotmail.com> wrote: Hi,
I'd like to create a Guid constant and the following doesn't work (Cannot implicitly convert type 'string' to 'System.Guid') :
public const Guid MyGuid = "{ccae2079-2ebc-4200-879d-866fc82e6afa}";
Ideas?
Thanks, Erik
public static readonly Guid MyGuid = new Guid ("{ccae2079-2ebc-4200-879d-866fc82e6afa}");
--
Tom Shelton [MVP] This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: BigDadyWeaver |
last post by:
I am using the following code in asp to define a unique and
unpredictable record ID in Access.
<%
'GENERATE UNIQUE ID
Function genguid()
Dim Guid
guid =...
|
by: Brent Horine |
last post by:
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);
...
|
by: Tomas Larsson |
last post by:
Hi.
I have some problems when using a static readonly declaration of a guid in a
switch/case statement. I'll give you an example.
public sealed class Activites
{
private Activites(){}
|
by: PawelF |
last post by:
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.
|
by: Nadav |
last post by:
Hi,
I am using the System.Type.GUID to identify similar types on different
computers, one computer send the GUID through a socket while the other
resolve the GUID and identify the type, when...
|
by: csharper |
last post by:
Why does Guid.GetHashcode() returns 0 when instantiated with Guid.Empty
?
|
by: M O J O |
last post by:
Hi,
Instead of doing this....
Public Class Form1
Public Shared Sub CreateAndShow()
Dim f As New Form1
f.Show()
End Sub
|
by: twang090 |
last post by:
Trying to create a 12 digit "guid", but have no idea on how to, anyone
please have any thought? Thanks in advance.
|
by: =?Utf-8?B?SlA=?= |
last post by:
I need to design a WS that will after authenicating the user, create a cookie
on the users PC that made the request. All the code I keep finding is how to
get a WS to read a cookie, I need it to...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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
|
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...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
| |