tailieunhanh - Apress - Accelerated C#_1

Accelerated C # 2010 là con đường nhanh nhất để làm chủ C #. Tất cả C # lập trình viên cần phải biết và hiểu như thế nào C # thực sự làm việc nhưng rất ít sách địa chỉ này. Không bao gồm nó ở độ sâu rằng điều này không. Nó dạy cho cả hai khái niệm ngôn ngữ cốt lõi C # và làm thế nào để sử dụng chúng trong mã hiệu suất cao. | CHAPTER 4 CLASSES STRUCTS AND OBJECTS You do not know the compiler-generated name of the type therefore you are forced to declare the variable instance as an implicitly typed local variable using the var keyword as I did in the code. Also notice that the compiler-generated type is a generic type that takes two type parameters. It would be inefficient for the compiler to generate a new type for every anonymous type that contains two types with the same field names. The output above indicates that the actual type of employeeinfo looks similar to the type name below fAnonymousType0 And because the anonymous type for customerinfo contains the same number of fields with the same names the generated generic type is reused and the type of customerinfo looks similar to the type below fAnonymousType0 Had the anonymous type for customerinfo contained different field names than those for employeeinfo then another generic anonymous type would have been declared. Now that you know the basics about anonymous types I want to show you an abbreviated syntax for declaring them. Pay attention to the bold statements in the following example using System public class ConventionalEmployeeinfo ._ public ConventionalEmployeeinfo string Name int Id Name Id public string Name get return name set name value public int Id get return id set id value private string name private int id public class EntryPoint 89 CHAPTER 4 CLASSES STRUCTS AND OBJECTS static void Main ConventionalEmployeeInfo oldEmployee new ConventionalEmployeeInfo Joe 42 var employeeinfo new string Name Jane int id 1234 var customerinfo new Name Id employeeInfo Name 0 Id 1 customerInfo Name 0 Id 1 Anonymous Type is actually 0 For illustration purposes I have declared a type named

TỪ KHÓA LIÊN QUAN