[csharp] //電話簿類Person.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 簡單電話薄 { class Person { string name;//姓名 string phone;//電話 public string Name { set { name =value; } get { return name; } } public string Phone { set { phone = value; } get { return phone; } } } } //主程序Program.cs using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 簡單電話薄 { class Program { /// <summary> /// 簡單電話簿 /// </summary> /// <param name="args"></param> static void Main(string[] args) { Console.Title = "簡單電話薄";//控制台標題 ArrayList telArray = new ArrayList();//用於存放電話 while (true) { Console.Clear();//清空控制台 Console.WriteLine("*******簡單電話薄*********"); Console.WriteLine("* 歡迎使用本系統 *"); Console.WriteLine("**************************"); Console.WriteLine("*a.添加, v.查看, q,退出*");//簡單提示界面 string select = Console.ReadLine().ToString(); if (select == "a")//添加電話 { Console.Write("請輸入姓名:"); string name = Console.ReadLine(); Console.Write("請輸入電話:"); string phone = Console.ReadLine(); telArray.Add(new Person() { Name = name, Phone = phone }); } else if (select == "v")//查看電話 { Console.Clear(); Console.WriteLine("電話號碼薄"); Console.WriteLine("姓名 電話"); foreach (object person in telArray) { Console.WriteLine("{0} {1}", ((Person)person).Name, ((Person)person).Phone); } Console.Read(); } else if(select =="q")//退出程序 { www.2cto.com Console.Clear(); Console.WriteLine("歡迎使用,謝謝!!"); Console.ReadKey(); return; } } } } }