C#程序设计(十二)----(体验接口)

* 程序的版权和版本声明部分
* Copyright (c) 2012, 烟台大学计算机学院学生
* All rights reserved.

* 作 者: 刘镇
* 完成日期: 2012 年 10 月 19 日
* 版 本 号: 3.012

* 对任务及求解方法的描述部分

* 问题描述:一个学生类实现的接口

 

*代码部分:

 

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace stu_Student
{
    public interface study
    {
        void readBook(string subject);
    }

    public interface live
    {
        string startTime { set; get; }
        string overTime { set; get; }
        void sleep();
        void playGame();
    }

    public struct Student : study, live
    {
        public void readBook(string subject)
        {
            Console.WriteLine("读" + subject + "书....");
        }

        public string startTime { set; get; }
        public string overTime { set; get; }

        public void sleep()
        {
            Console.WriteLine("呼呼呼.....从" + startTime + "睡到" + overTime);
        }

        public void playGame()
        {
            Console.WriteLine("嘻嘻哈哈.....从" + startTime + "玩到" + overTime);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Student stu = new Student();
            stu.readBook("にほんご");
            stu.startTime = "晚上10:00";
            stu.overTime = "早晨8:00";
            stu.sleep();
            stu.startTime = "上午9:00";
            stu.overTime = "中午12:00";
            stu.playGame();
            Console.ReadKey(true);
        }
    }
}


 

结果展示:

 

 

 

 

心得经验:

 

接口还是只有在自己体会了才能更有体会哟。。看书不是最主要。

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章