Quantcast
Channel: CSDN博客推荐文章
Viewing all articles
Browse latest Browse all 35570

C# 小程序之新手练习(二)简单电话簿

$
0
0
//电话簿类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;
                }
            }
        }
    }
}




作者:lingyunjinzhu 发表于2013-2-23 1:14:03 原文链接
阅读:116 评论:0 查看评论

Viewing all articles
Browse latest Browse all 35570

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>