5、委托 delegate double yun Suan(double n1, double n2) stat ic double Mul tiply ( double n1, double n2)=>n1 n2 static double Divide double n1, double n2)=>n1 /n2 static void Main(string[ args double d1 double Parse( readL ine o) double d2= double Parse(ReadLine o) Writeline("请输入*或者/:") str ing str ReadL o yunsuan ys f ( st ys Multipl //ys new yun Suan (Multiply) e se ys Divide / new yunsuan (DIVI Writel ine(ys(d1, d2))
5、委托
3.2 System. Col| ections Generic t称空间 ■这个名称空间包含用于处理集合的泛型类型,可以用于创建强类型 化的集合类。 ●List<T>T类型对象的集合 Dict ionary<K,V>与K类型的键值相关的V类型的项的集合 List<int> numJihe new List<int>o numJihe. Add (86) numJihe. Add(90) numJ ihe. Add (65) foreach (int n in numJ ihe) WriteL ine(s"in/ ")
3.2.2 System.Collections.Generic名称空间 这个名称空间包含用于处理集合的泛型类型,可以用于创建强类型 化的集合类。 List<T> T类型对象的集合 Dictionary<K,V> 与K类型的键值相关的V类型的项的集合
1、List<T 使用List<T存储 An ima集合,不需要定义单独的集合类 型。 List<An imaI> an i Jihe new List<An imaI>O animal Jihe. Add (new Cow("Rual")) animal Jihe. Add (new Chicken("Donna")) foreach (Animal a in an ima l Jihe) a Feed o
1、 List<T> 使用List<T>存储Animal集合,不需要定义单独的集合类 型
1、List<T 与上一章定义 An ima s集合类比较: public class Animals CollectionBase public void Add(Animal newAnimal) ist. Add(newAnimal) public void Remove(Animal newAnimal) List. Remove (newAnimal) WriteLine( "Using custom collection class Animals: Animals animalCollection new AnimalsO animal Collection. Add(new Cow(Lea) foreach (Animal myAnimal in animalcollection) WriteLine($"New fmy Animal ToString (]object added to custom collection, name= myAni mal Name]) Console. ReadKey o
1、 List<T> 与上一章定义Animals集合类比较: