namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Student stu = new Student(null);
Console.WriteLine(stu.Name);
}
}
class Student
{
public string Name;
public Student(string initName)
{
if (!string.IsNullOrEmpty(initName))
{
this.Name = initName;
}
else
{
throw new ArgumentException("initName 不能为空");
}
}
}
}
c# 取反运算符(!) 和 通过构造方法赋值并判断参数是否为空
最新推荐文章于 2023-05-04 04:48:08 发布