void Foo<T>() where T : new(string, int), enum, delegate
obj?.Name = "sdf"; //obj为null则什么也不做
public T this<T>[int i]{ get { return (T)arr[i]; } set { arr[i] = value; }}
public static var Create<T1, T2>(T1 arg1, T2 arg2){ return new { Item1 = arg1, Item2 = arg2 };}
if (int.TryParse("3", out int i)) //结合类型推断,甚至连int都允许省略{ Use(i);}
public static class Package{ static readonly Dictionary<string, int> _dic; static Package() { _dic = new Dictionary<string, int>(3); _dic.Add("a", 0); _dic.Add("b", 1); _dic.Add("c", 2); } public static int this[string name] { get { return _dic[name]; } set { _dic[name] = value; } }}// use exampleUse(Package["b"]);
暂时就扯这些,有新想法再补上。
新闻热点
疑难解答