我有一个类,在其中我现在有三个属性。如果在对象中任何一个是空或null,那么我想从对象中删除它。以下是我的代码。
public class TestClass
{
public string Name { get; set; }
public int ID { get; set; }
public DateTime? DateTime { get; set; }
public string Address { get; set; }
}
TestClass t=new TestClass();
t.Address="address";
t.ID=132;
t.Name=string.Empty;
t.DateTime=null;
现在我想要TestClass对象,但是该对象中的Name和DateTime属性不应存在,这有可能吗? 请帮帮我。