/*
* 结构体使用
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication2
{
struct Point
{
public int x, y;
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
}
class Program
{
static void Main(string[] args)
{
Point point = new Point(23, 67);
Console.WriteLine("x={0},y={1}", point.x, point.y);
Console.ReadKey();
}
}
}
运行结果:
x=23,y=67
/*
* 使用枚举来表示交通灯可能的颜色
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication2
{
enum Color { Red, Yellow, Green }
class TrafficLight
{
public static void WhatInfo(Color color)
{
switch (color)
{
case Color.Red:
Console.WriteLine("Stop!");
break;
case Color.Yellow:
Console.WriteLine("Warning!");
break;
case Color.Green:
Console.WriteLine("Go!");
break;
}
}
}
class Program
{
static void Main(string[] args)
{
Color c = Color.Red;
Console.WriteLine(c.ToString()); //枚举类型可以和字符串相互转化,ToString()方法可以将枚举成员转化为相对应的成员的名字
TrafficLight.WhatInfo(c);
Console.ReadKey();
}
}
}
运行结果:
Red
Stop!