C# · 12月 20, 2021

[读书笔记]C#学习笔记四: C#2.0泛型 可控类型 匿名方法和迭代器

<p style=”background: gray; color: #ffffff; font-size: 18pt;”>前言

1,泛型1.1 泛型是什么的数据类型分离,实现了代码重用。

Main( List intList = List intList.Add( List stringList = List stringList.Add( }

是.Net 类库中实现的泛型类型,T是泛型参数(可理解为形参), 如果想实例化一个泛型类型,必须传入实际的参数类型。

DictionaryStringKey : Dictionary Main( 是一个开放类型,它有两个类型参数 Type t = (Dictionary 是一个封闭类型 t = (DictionaryStringKey }

TypeWithStaticField Console.WriteLine(field + + Main( TypeWithStaticField.field = TypeWithStaticField.field = TypeWithStaticField.field = NoGenericTypeWithStaticField.field = NoGenericTypeWithStaticField.field = NoGenericTypeWithStaticField.field = TypeWithStaticField TypeWithStaticField TypeWithStaticField }

类型,即可空类型. C# 2.0 提供和的可空类型是Nullable和Nullable. (可控类型的定义是public struct Nullable where T:struct,T只能为值类型)

Nullable value = 1;

Nullable nullable = ? nullableWithoutValue = ,这一点需要特别注意 nullable.GetType(); obj = obj.GetType(); value = ( nullable = (?)obj;

VoteDelegate( Main( VoteDelegate VoteDelegate = VoteDelegate( VoteDelegate( Vote( Console.WriteLine( }

VoteDelegate( Main( VoteDelegate VoteDelegate = ( Console.WriteLine( VoteDelegate( }

接口.

[DispId(- }

[ComVisible( [Guid( Current { }

Name { ; Age { ; Person[] personList = Person[ personList[] = Person() { Name = ,Age = personList[] = Person() { Name = ,Age = personList[] = Person() { Name = ,Age = personList[] = Person() { Name = ,Age = Main( People p = (Person person Console.WriteLine( IEnumerator i = Person person = Console.WriteLine( }

Main( Friends friendCollection = (Friend f { { name = Friend( .name = friendarray = Friend( Friend( Friend( Friend [ { { ( i = ; i < friendarray.Length; i++ }

PS: 这两天比较闲 便更新的比较频繁. 写完这个系列也等于把这本书又重新读了一遍,仍有不少的收获.  勉励自己多读书,多记录,加油! 2016/01/20