日期:2014-05-17 浏览次数:20960 次
//电话簿类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")//退出程序 { Console.Clear(); Console.WriteLine("欢迎使用,谢谢!!"); Console.ReadKey(); return; } } } } }