例如,我有一个Vehicles继承自 MobileObjects. 那Vehicles类有10meters,23meters,12meters 作为数据。
我将如何将该信息添加到该数组中?
static void Main(string[] args) {
Console.WriteLine("hello");
MobileObjects[] array = new MobileObjects[3];
MobileObjects mob = new MobileObjects();
mob.setName("Jawaharal");
mob.setPosition();
mob.getID();
array[0] = mob;
MobileObjects mob1 = new MobileObjects();
mob1.setName("Willow");
mob1.setPosition();
array[1] = mob1;
MobileObjects mob2 = new MobileObjects();
mob2.setName("Indira");
mob2.setPosition();
array[2] = mob2;
foreach (MobileObjects host in array) {
Console.WriteLine("Name : " + host.Name + " ");
Console.WriteLine("ID : " + host.id);
Console.WriteLine("Position: " +
host.Position[0] + " " +
host.Position[1] + " " +
host.Position[2]);
}
}
泛舟湖上清波郎朗
相关分类