C#语言使用(C# language usage)

动态类型

1. 什么是动态类型?C#是一种静态类型的语言,使用静态类型的好处是C#编译器可以在编译时检查大部分的工作,能够找出更多的错误,使程序更加健壮。优先使用静态类型,静态类型比动态类型更高效,动态类型和在运行时创建表达式树都会带来性能上的影响。C#中的动态类型只是给你一种解决数据类型的一种方案,主要是与使用动态类型的环境进行交互使用的。2.动态类型基本语法在C#中,动态类型使用dynamic关键字表示,动态类型是在运行时解析,与var推断类型是完全不一样的,var还是静态类型,可推断出类型。3. 方法返回动态类型C#中的dynamic动态类型是可以作为方法的返回类型存在的。

base、this关键字

Base关键字,主要是应用于类的继承,可以在子类的构造函数、方法、属性实例属性中引用父类中的公有(public)有以及受保护(protected)的 方法、字段、属性、索引器等。关键字用于从子类中访问父类成员。即使父类的方法在子类中重写,仍可以使用base关键字调用。this关键字,主要是引用当前实例或者继承的方法。对于多层继承的情况:若存在重载:base指向直接继承的父类的重载的方法、字段等;即 Line 53若不存在重载:base指向任意层父类的方法、字段等。即 Line 53 base.PropertyA

————————

Dynamic type

1. What is a dynamic type? C # is a statically typed language. The advantage of using static types is that the C # compiler can check most of the work at compile time, find out more errors and make the program more robust. Static types are preferred. Static types are more efficient than dynamic types. Dynamic types and creating expression trees at run time will have a performance impact. Dynamic types in C # only give you a solution to data types, which are mainly used interactively with the environment using dynamic types. 2. Basic syntax of dynamic type in C #, dynamic type is represented by dynamic keyword. Dynamic type is resolved at runtime, which is completely different from VAR inference type. VaR is still a static type, and the type can be inferred. 3. The dynamic dynamic type c# in the method return dynamic type can exist as the method return type.

Base, this keyword

The base keyword is mainly applied to class inheritance. It can refer to the public and protected methods, fields, properties and indexers in the parent class in the constructor, method and attribute instance properties of the child class. Keyword is used to access parent class members from subclasses. Even if the method of the parent class is overridden in the child class, it can still be called with the base keyword. This keyword refers to the current instance or inherited method. In the case of multi-level inheritance: if there is an overload: the base points to the overloaded methods and fields of the directly inherited parent class; That is, if there is no overload in line 53, the base points to the methods and fields of any layer’s parent class. Line 53 base.propertya