* 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);
}
}
}
結果展示:
心得經驗:
接口還是只有在自己體會了才能更有體會喲。。看書不是最主要。