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);
        }
    }
}


 

結果展示:

 

 

 

 

心得經驗:

 

接口還是只有在自己體會了才能更有體會喲。。看書不是最主要。

 

 

 

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