小编Gne*_*nex的帖子

在另一个接口C#中使用List <interface>

我正在尝试在ASP.NET MVC2中为模型类创建一个接口,我想知道我是否可以List<interface>在另一个接口中使用.如果我给出一个代码示例,那会更好.

我有两个接口,一个终端可以有多个托架.所以我编码我的接口如下.

海湾接口:

public interface IBay
{
    // Properties
    int id {get; set;}
    string name {get;set;}
    // ... other properties
}
Run Code Online (Sandbox Code Playgroud)

终端接口:

public interface ITerminal
{
    // Properties
    int id {get;set;}
    string name {get;set;}
    // ... other properties
    List<IBay> bays {get;set;}
}
Run Code Online (Sandbox Code Playgroud)

我的问题是当我基于这些接口实现我的类时,如何设置托架列表.我是否必须在ITerminal界面之外和具体实现中进行托架列表?

我的目标是能够做到以下几点:

具体实施:
湾类:

class Bay : IBay
{
    // Constructor
    public Bay()
    {
        // ... constructor
    }
}
Run Code Online (Sandbox Code Playgroud)

终端类:

class Terminal : ITerminal
{
    // Constructor
    public Terminal()
    {
        // ... constructor
    }
} …
Run Code Online (Sandbox Code Playgroud)

c# interface asp.net-mvc-2

5
推荐指数
2
解决办法
1310
查看次数

标签 统计

asp.net-mvc-2 ×1

c# ×1

interface ×1