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 展开
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 展开
1个回答
展开全部
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);
}
}
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);
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询