C#学习小记12实现一个接口
生活随笔
收集整理的這篇文章主要介紹了
C#学习小记12实现一个接口
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
//實現一個接口
using System;
public interface ITeacher
{
bool AgreeToTeach();????? //注意!無需用public abstract
void Print(string b);???? //注意!無需用public abstract
}???????????????????????? //聲明一個接口
public class Professor:ITeacher?????? //實現接口
{
private int course;
public int Course
{
?? set{course=value;}
?? get{return course;}
}
public bool AgreeToTeach()?? //無需用override
{
?? if(Course==1)
???? return true;
?? else
???? return false;
}
public void Print(string a)
{
?? Console.WriteLine(this.AgreeToTeach()+a);
}
static void Main()
{
?? Professor a=new Professor();
?? a.Course=1;
?? a.Print("! this is yatasoft");
}
}
using System;
public interface ITeacher
{
bool AgreeToTeach();????? //注意!無需用public abstract
void Print(string b);???? //注意!無需用public abstract
}???????????????????????? //聲明一個接口
public class Professor:ITeacher?????? //實現接口
{
private int course;
public int Course
{
?? set{course=value;}
?? get{return course;}
}
public bool AgreeToTeach()?? //無需用override
{
?? if(Course==1)
???? return true;
?? else
???? return false;
}
public void Print(string a)
{
?? Console.WriteLine(this.AgreeToTeach()+a);
}
static void Main()
{
?? Professor a=new Professor();
?? a.Course=1;
?? a.Print("! this is yatasoft");
}
}
轉載于:https://www.cnblogs.com/yatasoft/archive/2008/08/06/1261943.html
總結
以上是生活随笔為你收集整理的C#学习小记12实现一个接口的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 25岁以上程序员单身手册
- 下一篇: SQL Injection(SQL注入)