我划下来的1号句子是什么意思啊

weikeli19 2016-05-03 04:16:24
如图:
请问我划下来的1号句子是什么意思啊?什么叫简单数组是强类型化的?
...全文
191 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
weikeli19 2016-05-03
  • 打赏
  • 举报
回复
引用 3 楼 shingoscar 的回复:
我估计他的意思就是和ArrayList做个区别
class X
{
    public void Feed() {}
}

X[] array = new X[] { new X() };
ArrayList arrayList = new ArrayList { new X() };

array[0].Feed();
arrayList[0].Feed(); //不行
我理解这位老师的意思了 谢谢各位了 我能把这本书看完 也算是你们的本事加上我的本事!
weikeli19 2016-05-03
  • 打赏
  • 举报
回复
引用 3 楼 shingoscar 的回复:
我估计他的意思就是和ArrayList做个区别
class X
{
    public void Feed() {}
}

X[] array = new X[] { new X() };
ArrayList arrayList = new ArrayList { new X() };

array[0].Feed();
arrayList[0].Feed(); //不行
书上的源代码是这样的: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections; namespace Ch11Ex01 { public abstract class Animal { protected string name; public string Name { get { return name; } set { name = value; } } public Animal() { name = "The animal with no name"; } public Animal(string newName) { name = newName; } public void Feed() { Console.WriteLine("{0} has been fed.", name); } } public class Chicken : Animal { public void LayEgg() { Console.WriteLine("{0} has laid an egg.", name); } public Chicken(string newName) : base(newName) { } } public class Cow : Animal { public void Milk() { Console.WriteLine("{0} has been milked.", name); } public Cow(string newName) : base(newName) { } } class Program { static void Main(string[] args) { Console.WriteLine("Create an Array type collection of Animal " + "objects and use it:"); Animal[] animalArray = new Animal[2]; Cow myCow1 = new Cow("Deirdre"); animalArray[0] = myCow1; animalArray[1] = new Chicken("Ken"); foreach (Animal myAnimal in animalArray) { Console.WriteLine("New {0} object added to Array collection, " + "Name = {1}", myAnimal.ToString(), myAnimal.Name); } Console.WriteLine("Array collection contains {0} objects.", animalArray.Length); animalArray[0].Feed(); ((Chicken)animalArray[1]).LayEgg(); Console.WriteLine(); Console.WriteLine("Create an ArrayList type collection of Animal " + "objects and use it:"); ArrayList animalArrayList = new ArrayList(); Cow myCow2 = new Cow("Hayley"); animalArrayList.Add(myCow2); animalArrayList.Add(new Chicken("Roy")); foreach (Animal myAnimal in animalArrayList) { Console.WriteLine("New {0} object added to ArrayList collection," + " Name= {1}", myAnimal.ToString(), myAnimal.Name); } Console.WriteLine("ArrayList collection contains {0} objects.", animalArrayList.Count); ((Animal)animalArrayList[0]).Feed(); ((Chicken)animalArrayList[1]).LayEgg(); Console.WriteLine(); Console.WriteLine("Additional manipulation of ArrayList:"); animalArrayList.RemoveAt(0); ((Animal)animalArrayList[0]).Feed(); animalArrayList.AddRange(animalArray); ((Chicken)animalArrayList[2]).LayEgg(); Console.WriteLine("The animal called {0} is at index {1}.", myCow1.Name, animalArrayList.IndexOf(myCow1)); myCow1.Name = "Janice"; Console.WriteLine("The animal is now called {0}.", ((Animal)animalArrayList[1]).Name); Console.ReadKey(); } } }
xuzuning 2016-05-03
  • 打赏
  • 举报
回复
好拗口的语句 你最好结合前面对 animalArray 的定义和赋值来理解
Poopaye 2016-05-03
  • 打赏
  • 举报
回复
我估计他的意思就是和ArrayList做个区别
class X
{
    public void Feed() {}
}

X[] array = new X[] { new X() };
ArrayList arrayList = new ArrayList { new X() };

array[0].Feed();
arrayList[0].Feed(); //不行
  • 打赏
  • 举报
回复
意思就是下面这种
int[]
Animal[]
JoeBlackzqq 2016-05-03
  • 打赏
  • 举报
回复
简单数组,我感觉应该是基础数据类型组成的数组!

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧