21.1使用集合 ■ System. Array类实现了 IList、 I Collect ion、 l Numer able,但不支持list的一些高级功能,它表示 大小固定的项列表。 System. Col lections. ArrayList类也实现了 IList、 I Collect ion、 I Enumerable,但实现方式比 System array更复杂
2.1.1 使用集合 System.Array类实现了IList、ICollection、 IEnumerable,但不支持Ilist的一些高级功能,它表示 大小固定的项列表。 System.Collections.ArrayList类也实现了IList、 ICollection、IEnumerable,但实现方式比 System.Array更复杂
System Array和 System Co| lections. ArrayList的使用举例 public abstract class Animal protected string name public string Na get i return name set value public Animal O name The animal wi th no name public Animal(string newName name = newName public void Feed(=>WriteLine($"name] has been fed.
System.Array和System.Collections.ArrayList的使用举例
System Array和 System Co| lections. ArrayList的使用举例 public class Cow Animal public void Milko=>WriteLine($"iname] has been milked. public Cow(string newName): base(newName)0 public class Chicken Animal public void LayEgg(=>WriteLine("name] has laid an egg. " public Chicken(string newName): base (newName)0
System.Array和System.Collections.ArrayList的使用举例
System Array和 System Co| lections. ArrayList的使用举例 static void Main(string[] args) WriteLine("Create an Array type collection of Animal objects and use it: Animal l animal Array new Animal [2] Cow my Cowl new Cow( Lea animalArray [o]= mrCow1 animalArray [1]= new Chicken("Noa") foreach (Animal myAnimal in animalArray WriteLine($"New fmy Animal ToString O) object added to Array collection, Name= imyAnimal Name]") WriteLine($"Array collection contains animal Array Length objects. animalArray [o]. FeedO ((Chicken)animal Array[1]). Layeggo WriteLineo
System.Array和System.Collections.ArrayList的使用举例
System Array和 System Co| lections. ArrayList的使用举例 WriteLine("Create an ArrayList type collection of Animal objects and use it: Arraylist animalArrayList new ArrayList o Cow my Cow2= new Cow(Rual") animalArrayList. Add (my Cow2) animalArrayList. Add (new Chicken( Andrea ) foreach (Animal myAnimal in animalArrayList) WriteLine($"New myAnimal. ToString(] object added to ArrayList collection, Name= fmy Animal Name]") WriteLine(s"ArrayList collection contains fanimalArrayList Count] objects. ((Animal)animalArrayList[o]). FeedO ((Chicken) animalArrayList[1]). LayEggo WriteLine o
System.Array和System.Collections.ArrayList的使用举例