P
Paul Selormey
There is many things in the design of the .NET type system
I do not understand why it should be like that:
1. Why are we not allowed to provide parameterless constructors
for value types? (I find it a large limitation, since I sometimes
need defaults/initialization other than the process provides)
2. Why is the ValueType derived from Object?
3. Since the derivation of ValueType from Object, makes it a class
why boxing?
4. Why is "ValueTypeArray" not provided instead of just Array for
everything?
5. Why is there no common base ValueType for numerics/numbers?
I recently found myself writing a class like,
public class TestClass
{
private ValueType m_valueMax;
public TestClass(ValueType value)
{
m_valueMax = value;
}
public ValueType Value
{
get
{
return m_valueMax;
}
}
}
instead of
public class TestClass
{
private object m_valueMax;
public TestClass(object value)
{
m_valueMax = value;
}
public object Value
{
get
{
return m_valueMax;
}
}
}
because I simply needed a number to be passed it, and do not
need to be doing stuff like
if (value == null)
throw new ArgumentNullException("value");
Best regards,
Paul.
I do not understand why it should be like that:
1. Why are we not allowed to provide parameterless constructors
for value types? (I find it a large limitation, since I sometimes
need defaults/initialization other than the process provides)
2. Why is the ValueType derived from Object?
3. Since the derivation of ValueType from Object, makes it a class
why boxing?
4. Why is "ValueTypeArray" not provided instead of just Array for
everything?
5. Why is there no common base ValueType for numerics/numbers?
I recently found myself writing a class like,
public class TestClass
{
private ValueType m_valueMax;
public TestClass(ValueType value)
{
m_valueMax = value;
}
public ValueType Value
{
get
{
return m_valueMax;
}
}
}
instead of
public class TestClass
{
private object m_valueMax;
public TestClass(object value)
{
m_valueMax = value;
}
public object Value
{
get
{
return m_valueMax;
}
}
}
because I simply needed a number to be passed it, and do not
need to be doing stuff like
if (value == null)
throw new ArgumentNullException("value");
Best regards,
Paul.