各种例子

1,枚举:

public enum TimeOfDay
{
Morning = 0,
Afternoon = 1,
Evening = 2
}

class EnumExample
{
public static int Main()

{
WriteGreeting(TimeOfDay.Morning);
return 0;
}

   static void WriteGreeting(TimeOfDay timeOfDay)
{
switch(timeOfDay)
{
case TimeOfDay.Morning:
Console.WriteLine("Good morning!");
break;
case TimeOfDay.Afternoon:
Console.WriteLine("Good afternoon!");
break;
case TimeOfDay.Evening:
Console.WriteLine("Good evening!");
break;
default:
Console.WriteLine("Hello!");
break;
}
}
}

 

2,Main方法参数的使用

using System;

namespace Wrox.ProCSharp.Basics
{
class ArgsExample
{
public static int Main(string[] args)
{
for (int i = 0; i < args.Length; i++)
{
Console.WriteLine(args[i]);
}
return 0;
}
}
}

ArgsExample /a /b /c
/a
/b
/c

posted @ 2012-12-07 10:41  sxw521  阅读(40)  评论(0)    收藏  举报