public class NewAtturibute
{
public void TestFunc()
{
// 01 Out变量 不用初始化
string input = "111";
if (int.TryParse(input, out int a))
{
}
// 02 Is表达式
object obj = new object();
if (obj is int i) // 这个地方直接做了转化
{
int s = i + 2;
Console.WriteLine($"{s}");
}
// 04 定义元组
// 方式1
(string Name, int Age) ss = (Name: "", Age: 2);
Console.WriteLine($"{ss.Name}");
//方式2
var tuple = (Name: "11", Age: 1);
Console.WriteLine($"{tuple.Name}");
//调用方法
var t = GetInfo();
Console.WriteLine(t.Name);
}
//元组作为方法的返回值
public (string Name, int Age, decimal d) GetInfo()
{
return ("11", 2, 22m);
}
public void Create() => new ClassOne();
private string _str;
// 03 这里可以抛异常
public string IsNull => _str ?? throw new Exception("~~~");
}