class SuperMarket
{
private Queue<string> a;
private Queue<string> b;
public SuperMarket()
{
this.a = new Queue<string>();
this.b = new Queue<string>();
}
public void InsertToA(string name)
{
this.a.Insert(name);
}
public void InsertToB(string name)
{
this.b.Insert(name);
}
这是主程序:
public static void Main(string[] args)
{
SuperMarket a = new SuperMarket();
Console.WriteLine("Enter Names For first");
string name = Console.ReadLine();
while (name.CompareTo("aaa") != 0)
{
a.InsertToA(name);
name = Console.ReadLine();
}
Console.WriteLine("Enter Names For second");
name = Console.ReadLine();
while (name.CompareTo("aaa") != 0)
{
a.InsertToB(name);
name = Console.ReadLine();
}
}
非常感谢!!!!!
答案 0 :(得分:0)
几年后,我可以轻松回答自己的问题:
public void InsertToA(string name)
{
this.a.Enqueue(name);
}
public void InsertToB(string name)
{
this.b.Enqueue(name);
}
->在c#中使用泛型时,应该使用Enqueue而不是Insert。