C#中在主方法中定义一个数组,并且要在其他类中调用此数组应该怎么做

usingSystem;publicinterfaceIbooker{voidlook();}classlooker:Ibooker{publicvoidlook(boo... using System;
public interface Ibooker
{
void look();
}
class looker:Ibooker
{
public void look(book []boo)
{
for (int i = 0; i < boo.Length; i++)
{
Console.WriteLine(boo[i].no+""+boo[i].name+""+boo[i].writer+""+boo[i].chuban+""+boo[i].prise+"");
}
}
}
class finder:Ibooker
{
public void look(book []boo)
{
Console.Write("请输入所要查找的图书编号(如01):");
string sn = Console.ReadLine();
int n = -1;
for (int i = boo.Length - 1; i >= 0; i--)
{
if (boo[i].no == sn)
{
n = i; break;
}
if (n == -1)
{
Console.WriteLine("无此图书信息,查找失败!!");
}
else
{
Console.Write(boo[n].no+"");
Console.Write(boo[n].name+"");
Console.Write(boo[n].writer + "");
Console.Write(boo[n].chuban + "");
Console.Write(boo[n].prise + "");
}
}
}
}
class onwer
{
public void onwers(Ibooker k1)
{
k1.look();
}
}
public struct book
{
public string no, name, writer, chuban;
public double prise;
}
class test
{
static void Main()
{
onwer n1 = new onwer();
Console.WriteLine("###############################################################################");
Console.WriteLine(" # #");
Console.WriteLine(" # 欢迎进入图书系统 #");
Console.WriteLine(" # #");
Console.WriteLine("###############################################################################");
Console.WriteLine(" 功能选项:");
Console.WriteLine(" 1:查找全部图书信息");
Console.WriteLine(" 2:通过图书编号查找图书信息");
Console.WriteLine("###############################################################################");
Console.Write("请在查看功能选项后进行选择:");
int m = int.Parse(Console.ReadLine());
for (int i = 0; i <= 10; i++)
{
switch (m)
{
case 1: n1.onwers(new looker()); break;
case 2: n1.onwers(new finder()); break;
default: Console.WriteLine("选项错误!"); break;
}
}
book[] boo = new book[10];

}

}
程序完成后提示错误信息:looker与finder没有继承接口booker
展开
 我来答
工程师首岳
2014-06-07 · TA获得超过278个赞
知道小有建树答主
回答量:162
采纳率:100%
帮助的人:102万
展开全部
using System;
public interface Ibooker
{
void look();
}
class looker : Ibooker
{
public void look(book[] boo)
{
for (int i = 0; i < boo.Length; i++)
{
Console.WriteLine(boo[i].no + "" + boo[i].name + "" + boo[i].writer + "" + boo[i].chuban + "" + boo[i].prise + "");
}
}

//looker继承了ibooker,就要实现Ibooker的look()方法
public void look()
{ }
}
class finder : Ibooker
{
public void look(book[] boo)
{
Console.Write("请输入所要查找的图书编号(如01):");
string sn = Console.ReadLine();
int n = -1;
for (int i = boo.Length - 1; i >= 0; i--)
{
if (boo[i].no == sn)
{
n = i; break;
}
if (n == -1)
{
Console.WriteLine("无此图书信息,查找失败!!");
}
else
{
Console.Write(boo[n].no + "");
Console.Write(boo[n].name + "");
Console.Write(boo[n].writer + "");
Console.Write(boo[n].chuban + "");
Console.Write(boo[n].prise + "");
}
}
}

//finder继承了ibooker,就要实现Ibooker的look()方法
public void look()
{ }
}
class onwer
{
public void onwers(Ibooker k1)
{
k1.look();
}
}
public struct book
{
public string no, name, writer, chuban;
public double prise;
}
class test
{
static void Main()
{
onwer n1 = new onwer();
Console.WriteLine("###############################################################################");
Console.WriteLine(" # #");
Console.WriteLine(" # 欢迎进入图书系统 #");
Console.WriteLine(" # #");
Console.WriteLine("###############################################################################");
Console.WriteLine(" 功能选项:");
Console.WriteLine(" 1:查找全部图书信息");
Console.WriteLine(" 2:通过图书编号查找图书信息");
Console.WriteLine("###############################################################################");
Console.Write("请在查看功能选项后进行选择:");
int m = int.Parse(Console.ReadLine());
for (int i = 0; i <= 10; i++)
{
switch (m)
{
case 1: n1.onwers(new looker()); break;
case 2: n1.onwers(new finder()); break;
default: Console.WriteLine("选项错误!"); break;
}
}
book[] boo = new book[2];
book book = new global::book();
book.no = "01";
book.name = "书1";
boo[0] = book;
book = new global::book();
book.no = "02";
book.name = "书2";
boo[1] = book;

looker ibook = new looker();
ibook.look(boo);
}

}
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式