鉴于代码:
public class Filter<T>
{
private bool selected = false;
public bool Selected { get { return selected; } }
private T value;
public T Value { get{ return this.value; } set { this.value = value; selected = true; }
}
public class Test
{
public void filter()
{
DateTime a= new DateTime();
Nullable<DateTime> b = new DateTime(); //Work Like a Charm
Filter<DateTime> c = new DateTime(); //Dosent Work
}
}
Run Code Online (Sandbox Code Playgroud)
在Nullable<T>该new DateTime()可直接分配到变量.在我的班上,它不起作用.我想了解我所缺少的东西.
我觉得这很简单.但我无法用言语来找到答案.
c# class type-conversion conversion-operator implicit-conversion