2014-09-24 28 views
-2
class Program 
{ 

    public string name; 
    public string cell; 
    public Program(string a1,string c1) 
    { 
     name = a1; 
     cell = c1; 
    } 

    public void DetailAccept() 
    { 
     Console.WriteLine("enter name :"); 
     name = Console.ReadLine(); 
     Console.WriteLine("enter cell :"); 
     cell = Console.ReadLine(); 
    } 

    public string getName() 
    { 
    return name; 
    } 
    public string getCellNo() 
    { return cell; } 
    public void AddL(string a, string b, LinkedList<Program> linked) 
    { 
     Program p1 = new Program(a, b); 
     linked.AddLast(p1); 
    } 

    public void menu() 
    { 
     Console.WriteLine("\n Choose what to do :\n1. Add new Entry\n2. Search Phone\n3.quit\n"); 

     int choice = Convert.ToInt16(Console.ReadLine()); 
     switch(choice) 
     { 
      case 1: DetailAccept(); 
       AddL(getName(), getCellNo(), linked); // here is the problem . 

     } 
    } 
} 

我是否需要通過LinkedList作爲參數才能在函數中使用它?如果是,那麼如果不是,那麼如何選擇?如何將鏈接列表作爲參數傳遞給方法以及如何調用它?

+1

看來你已經有一些代碼。它有什麼問題? – 2014-09-24 14:59:52

+0

實例字段,屬性? – 2014-09-24 15:02:23

回答

1

你打算這樣嗎?

private LnkedList<Program> _Programs = new LinkedList<Program>(); 

public void menu() 
{ 
    Console.WriteLine("\n Choose what to do :\n1. Add new Entry\n2. Search Phone\n3.quit\n"); 

    int choice = Convert.ToInt16(Console.ReadLine()); 
    switch(choice) 
    { 
     case 1: DetailAccept(); 
      AddL(getName(), getCellNo(), _Programs); 

    } 
} 
+0

謝謝你的幫助。我是編程新手,這很愚蠢。 – 2014-10-04 08:54:00

相關問題