日期:2014-05-17 浏览次数:20982 次
/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称:设计结构和枚举,并测试之。
* 作 者: 雷恒鑫
* 完成日期: 2012 年 10 月 21 日
* 版 本 号: V1.0
* 对任务及求解方法的描述部分
* 输入描述:设计一个结构,并测试之。设计一个枚举,并测试之。
* 问题描述:
* 程序输出:
* 程序头部的注释结束
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
enum Color { Red, Yellow, Green }
namespace five_week
{
class Program
{
static void Main(string[] args)
{
Point point = new Point(23, 67);
Console.WriteLine("结构体经过测试 x = {0}, y = {1}",point.x,point.y);
Console.WriteLine();
Color c = Color.Red;
Console.WriteLine("枚举经过测试当显示红灯时为:{0}",c.ToString());
Console.ReadKey();
}
}
struct Point
{
public int x, y;
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
}
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;
}
}
}
}
运行结果:
