abstract
类最好用来声明公共const
变量
|
|
ReadOnlyCollection
替换Array
的readonly
|
|
Assembly
的代码
|
|
Cyclomatic Complexity(圈复杂度)
dynamic
弱语言的东西类似js的结构体,和模板搭配很好用Obsolete
12[Obsolete("该方法已被弃用,请使用NewMethod代替")]static void OldMethod()abstract
属性可以通过继承覆盖
···
public abstract class Shape
{
private string name;public Shape(string s)
{// calling the set accessor of the Id property. Id = s;
}
public string Id
{get { return name; } set { name = value; }
}
// Area is a read-only property - only a get accessor is needed:
public abstract double Area
{get;
}
public override string ToString()
{return $"{Id} Area = {Area:F2}";
}
}
public class Square : Shape
{
private int side;public Square(int side, string id)
: base(id)
{
this.side = side;
}
public override double Area
{get { // Given the side, return the area of a square: return side * side; }
}
}
···
is
的规则12345678910111213141516171819interface Animal { }class Cat : Animal { }class Dog : Animal { }static void Main(string[] args){List<Animal> animals = new List<Animal> { new Cat(), new Dog() };foreach (Animal a in animals){if (a is Cat)Console.WriteLine("Miaow!");if (a is Dog)Console.WriteLine("Woof!");if (a is Animal)Console.WriteLine("Animal!");}Console.ReadLine();Console.ReadKey();}// Miaow Animal Woof Animal引用用类型,值类型比较
引用类型:ReferenceEquals(null, x)
比较是否是指向同一内存
虚函数Equals
值类型:==
运算符比较
- 双重检查
lock