namespace 介面
{
class Program
{
public interface fly
{
Dream dream();
}
public class Dream
{
}
public class People : fly
{
public Dream dream()
{
Dream a = new Dream();
Console.WriteLine("a");
return a;
}
}
public class Animal : fly
{
public Dream dream()
{
Dream a = new Dream();
Console.WriteLine("b");
return a;
}
}
public class FF
{
fly activeDoment = null;//這里定義了一個介面欄位,sring 、int的賦值我明白,介面型欄位我不明白什么意思,也不知道如何賦值
//string str =“123”;
//int num = 3;
public fly ActiveDocument
{
get { return activeDoment; }
set {
activeDoment = value;
}
}
}
public class OrderList<T>: LinkedList<T>
{
public T FirstValue
{
get
{
if (First == null)
return default(T);
else
return First.Value;
}
}
}
static void Main(string[] args)
{
OrderList<fly> documentHistory = new OrderList<fly>();
FF ff = new FF();
Dream newDream = new Dream();
newDream = ff.ActiveDocument.dream();//報錯,未將物件引入實體,如何引入?
}
}
}
uj5u.com熱心網友回復:
fly activeDoment = new People();或
fly activeDoment = new Animal();
都可以。只要new出來的物件實作了fly介面就能賦值。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/71676.html
標籤:C#
上一篇:C#某個時間段的有效日期天數
