码迷,mamicode.com
首页 > Windows程序 > 详细

1.C# -- Switch 用法

时间:2015-05-12 11:41:45      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
    class Program
{
        static void Main(string[] args)
{
            const string myName = "karli";
            const string sexyName = "angelina";
            const string sillyName = "karli2";
            string name;
            Console.WriteLine("what‘s your name?");
            name = Console.ReadLine();
            switch (name.ToLower())
{
                case myName:
                    Console.WriteLine("You have the same name as me!");
                    break;
                case sexyName:
                    Console.WriteLine("My, what a sexy name you have!");
                    break;
                case sillyName:
                    Console.WriteLine("That‘s a very silly name!");
                    break;
}
            Console.WriteLine("Hello {0}! ",name);
            Console.ReadKey();
}
}
}

运行结果:

技术分享

本文出自 “Ricky's Blog” 博客,请务必保留此出处http://57388.blog.51cto.com/47388/1650503

1.C# -- Switch 用法

标签:c#

原文地址:http://57388.blog.51cto.com/47388/1650503

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!