c# - 用作变量的类型

标签 c#

我有一个简单的业务经理门面,它应该只保留一些库存信息。但是,我不断收到“Home.Services.InventorySvc”是一种用作变量的类型的错误。

我的门面代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Home.Domain;
using Home.Services;

namespace Home.Business
{
    public class InventoryMngr
    {
        public void Create(CreateInventory inv) 
        {
            Factory factory = Factory.GetInstance();
            InventorySvc invSvc =
            (InventorySvc)factory.GetService(
            (InventorySvc).Name);
            invSvc.CreateInventory(inv);
        }
    }
} 

InventorySvc 代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Home;
using Home.Domain;

namespace Home.Services
{
    public interface InventorySvc : IService
    {
        void CreateInventory(CreateInventory createinventory);
    }
}

最佳答案

您正在使用 (InventorySvc).NameInventorySvc.Name 相同,所以这将访问 InventorySvc 的静态成员类(class)。因为它不是一个类而是一个接口(interface),所以它不能有静态成员。

关于c# - 用作变量的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12664977/

相关文章:

c# - 正则表达式 - 正确的模式

c# - 满足 subview 模型依赖关系

c# - 7zip 压缩网络流

c# - 将 JSON 反序列化为 List<T> 时出错

c# - 从 Web 服务读取 XML 节点

c# - 如何将 Image<Gray, Byte> 转换为 Image<Gray, float>?

c# - 为什么这个正则表达式不匹配任何内容?

c# - Webmatrix - 将变量从 cshtml 页面传递到 aspx 页面

c# - 获取子字符串

c# - 将 LIST 中的数据保存到文本文件