int a;
float b;
//a = null;
//b = null;
//if (a == null || b == null)
//{
// //int a和float b必须赋值,并且a不能为null
// Console.WriteLine("a or b is null");
//也就是数字必须有非null的值
//}
string str;
//方法里的变量必须赋值;
str = null;
if (string.IsNullOrEmpty(str))
{
Console.WriteLine("string is null or empty");
}
MItem mItem = null;
if (mItem == null)
{
Console.WriteLine("class could be null");
}
mItem = new MItem();
if (mItem != null)
{
Console.WriteLine("赋过值的class不会为null");
}
Console.WriteLine(mItem.ck);//默认False
Console.WriteLine(mItem.dt.ToString("yyyy-MM-dd"));//默认0001-01-01;
Console.WriteLine(mItem.val);//decimcal默认0
Console.WriteLine(mItem.value);//int默认0
public class MItem
{
public string id { set; get; }
public DateTime dt { set; get; }
public decimal val { set; get; }
public int value { set; get; }
public string Rank { set; get; }
public List<string> idList { set; get; }
public bool ck { set; get; }
}
疑惑解答1
最新推荐文章于 2022-12-01 19:46:40 发布