O
Octavio Hernandez
Hi,
Don't see any problems with that...
Regards - Octavio
Don't see any problems with that...
Regards - Octavio
Yuriy said:Any comments on nullables in switch?
Yuriy said:which types are allowed in switch? string and integral types? or any
type, if there is only one way of implicit convertion to any of the types
mentioned above.
Nullable<> is neither string nor integral type, and I cannot find anything
where it is said that C# 2.0 enhances a list of types allowed in switch.
Yuriy said:What is Nullable<A> in this list? Do you know any implicit convertions
from A? to any of the types listed in spec?
Yuriy said:Nullable<Snum> is not enum itself. It is just value type, which has no
implicit conversion to niether the enum or listed type. so, according to
your explanation in cannot be used in switch, but it works.
How does it cover nullables? SomeEnum type is not base type for Nullable said:Yuri,
Quoting the C# Specification, 3rd Edition (p. 228):
"The governing type of a switch statement is established by the switch
expression. If the type of the switch
expression is sbyte, byte, short, ushort, int, uint, long, ulong,
char,
string, or an enum-type,
then that is the governing type of the switch statement. Otherwise,
exactly one user-defined implicit
conversion operator (§13.4) shall exist from the type of the switch
expression or a base type of this type to
one of the following possible governing types: sbyte, byte, short,
ushort, int, uint, long, ulong,
char, string. If no such implicit conversion operator exists, or if
more than one such implicit conversion
operator exists, a compile-time error occurs."
This covers the case of a nullable type as switch expression, right?
The standard is at www.ecma-international.org.
Privet - Octavio
Octavio Hernandez said:Yuri,
Quoting the C# Specification, 3rd Edition (p. 228):
"The governing type of a switch statement is established by the switch
expression. If the type of the switch
expression is sbyte, byte, short, ushort, int, uint, long, ulong, char,
string, or an enum-type,
then that is the governing type of the switch statement. Otherwise,
exactly one user-defined implicit
conversion operator (§13.4) shall exist from the type of the switch
expression or a base type of this type to
one of the following possible governing types: sbyte, byte, short, ushort,
int, uint, long, ulong,
char, string. If no such implicit conversion operator exists, or if more
than one such implicit conversion
an unwrapping from S? to S followed by the underlying conversion from S to T.
This allows for constructs like
int? foo = 42;
if (foo == 42)
MarkT said:The nullable conversion from S? to T is an Explicit conversion.
MarkT said:I just spent an hour looking at every place either nullable or switch
appears in the spec, and I could not find anything that explains the
behavior. However, the spec is pretty tough reading so I could easily have
missed something. I tentatively vote "bug" on this one. You could submit
it
as a bug in the Microsoft Product Feedback Center to get some official
word
on it.