I
Israel
I have the following class which gets this error when I compile it
using C# 2.0:
'System.Nullable<System.DayOfWeek>' does not contain a definition for
'Monday'
class MyClass
{
public MyClass()
{
m_DayOfWeek = DayOfWeek.Monday;
}
public DayOfWeek? DayOfWeek
{
get { return m_DayOfWeek; }
set { m_DayOfWeek = value; }
}
private DayOfWeek? m_DayOfWeek;
}
If I don't use a nullable type it compiles fine. I can understand
that it's a difficult parsing problem to realize that this should be
legal but it's always done such a good job figuring out what
"DayOfWeek" meant in the past based on the context so why has the
compiler given up in this situation and forced me to scope the enum
with "System."? Is there a situation where the compiler could
actually make the wrong decision and allow this to compile the wrong
code? I can see situations where it would be ambiguous if the enum
had a value "HasValue" and then the compiler could just say it's
ambiguous but if it's not ambiguous the compiler could just pick the
only valid option.
using C# 2.0:
'System.Nullable<System.DayOfWeek>' does not contain a definition for
'Monday'
class MyClass
{
public MyClass()
{
m_DayOfWeek = DayOfWeek.Monday;
}
public DayOfWeek? DayOfWeek
{
get { return m_DayOfWeek; }
set { m_DayOfWeek = value; }
}
private DayOfWeek? m_DayOfWeek;
}
If I don't use a nullable type it compiles fine. I can understand
that it's a difficult parsing problem to realize that this should be
legal but it's always done such a good job figuring out what
"DayOfWeek" meant in the past based on the context so why has the
compiler given up in this situation and forced me to scope the enum
with "System."? Is there a situation where the compiler could
actually make the wrong decision and allow this to compile the wrong
code? I can see situations where it would be ambiguous if the enum
had a value "HasValue" and then the compiler could just say it's
ambiguous but if it's not ambiguous the compiler could just pick the
only valid option.