- Why can't I use a constraint of
where T : System.ValueType
?
- Why does Microsoft prevent this type
from being a constraint?
Example:
Why can't I do the following?
// Defined in a .Net class
public void bar<T>(T a) where T : ValueType {...}
// Defined in my class
public void foo<T>(T a) where T : ValueType
{ bar<T>(a); }
What is the difference in using struct over ValueType?
// Defined in my class
public void foo<T>(T a) where T : struct
{ bar<T>(a); }
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…