C#接口问题,分不多,新手求大佬

huanyanfei5003 2020-02-05 03:37:21
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();//报错,未将对象引入实例,如何引入?
}
}
}
...全文
121 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
fanruinet 2020-02-08
  • 打赏
  • 举报
回复
fly activeDoment = new People(); 或 fly activeDoment = new Animal(); 都可以。只要new出来的对象实现了fly接口就能赋值。

111,089

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧