T
Tomas Larsson
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(){}
public static readonly Guid Read = new
Guid("AAAAAAAA-AAAA-AAAA-0001-AAAAAAAAAAAA");
}
Then I want to use this constant in a switch case statement like below:
switch(someGuid)
{
case Activities.Read:
//do something
break;
}
I thought one possible way was to convert both guids to strings instead,
since the case statmement accepts strings, but this will generate an error
"A constant value is expected".
Why is this, and how whould it be done instead? I don't want to declare the
constants as strings because I want them to have the correct type.
/Tomas Larsson
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(){}
public static readonly Guid Read = new
Guid("AAAAAAAA-AAAA-AAAA-0001-AAAAAAAAAAAA");
}
Then I want to use this constant in a switch case statement like below:
switch(someGuid)
{
case Activities.Read:
//do something
break;
}
I thought one possible way was to convert both guids to strings instead,
since the case statmement accepts strings, but this will generate an error
"A constant value is expected".
Why is this, and how whould it be done instead? I don't want to declare the
constants as strings because I want them to have the correct type.
/Tomas Larsson