Animal[] animalArray=new Animal[2];
Cow myCow1=new Cow("Deirdre");
animalArray[0]=myCow1;
visual c# 2010,不知道为什么错了,提示原因如标题
Cow myCow1=new Cow("Deirdre");
animalArray[0]=myCow1;
visual c# 2010,不知道为什么错了,提示原因如标题
解决方案 »
- ERP局域网实施
- C# 的一段代码,在windowmobile下正常,在winform下报错,各位高手帮忙看看是什么问题。
- C#文本操作求助!
- Server Application Error的问题
- winform 如何删除DataGridView 的第一列单元格
- 请问局域网中的机器通过代理服务器上网怎样才能与网上的机器进行通讯呢?
- XtraGrid中设置一列的编辑方式为LookUpEditor后,运行时该列不能马上显示其内容
- Session传值与oracle Varchar2的问题
- 日期格式转换?高分求代码
- 使用SQLDMO备份SQL出错
- c# socket编ftp客户端 Receive接收数据不全的问题
- Directory不是C#自带的类吗,怎么还提示上下文不存在呢?
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections ;namespace Ch11Ex01
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("create an array type collection of animal");}
Animal[] animalArray = new Animal[2];
Cow myCow1=new Cow("Deirdre");
animalArray[0] = myCow1;
}
}
animal类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;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);}
}
}Cow类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace Ch11Ex01
{
public class Cow:Animal
{
public void Milk() { Console.WriteLine("{0} has been milked",name);}
public Cow(string newName): base(newName) { }
}
}
编程习惯要养好
推荐一篇
http://topic.csdn.net/u/20120109/16/e523711d-9451-41e0-932f-5bcaa8a438a5.html