Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 可访问性不一致:属性类型';IPProductRepository';找不到_C#_Asp.net_Visual Studio_Repository - Fatal编程技术网

C# 可访问性不一致:属性类型';IPProductRepository';找不到

C# 可访问性不一致:属性类型';IPProductRepository';找不到,c#,asp.net,visual-studio,repository,C#,Asp.net,Visual Studio,Repository,错误:可访问性不一致:属性类型“IEnumerable”的可访问性不如属性“IPProductRepository.Products” namespace sportstore.Domain.Abstract { 公共接口存储库 { IEnumerable乘积{get;} } } 我不明白错误信息的意思;有人能帮我确定出什么问题吗?如果您有以下任何类定义: class Product // defaults to internal 或 然后,产品类型在部件外部不可见。如果定义此接口,则会发生

错误:可访问性不一致:属性类型“IEnumerable”的可访问性不如属性“IPProductRepository.Products”

namespace sportstore.Domain.Abstract
{
公共接口存储库
{
IEnumerable乘积{get;}
}
}

我不明白错误信息的意思;有人能帮我确定出什么问题吗?

如果您有以下任何类定义:

class Product // defaults to internal

然后,
产品
类型在部件外部不可见。如果定义此接口,则会发生冲突:

public interface IProductRepository
{
    IEnumerable<Product> Products { get; }            
}
公共接口存储库
{
IEnumerable乘积{get;}
}
这表示接口是公共的,从程序集外部可见。但这是不可能的,因为它包含一个类型-
产品
,在程序集外部不可见。它就像一家商店,出售任何顾客都不允许知道的产品。这没有道理

没有办法调和这种不一致性,因此编译器不会构建它


您可以将它们都设置为
内部
或同时设置为
公共
。您可以将界面
设置为内部
产品
公开
。但是您不能将界面
公开
产品
内部,因为它会产生冲突。

您的代码没有正确标记,因此很难使用。您的代码不完整,但我打赌您的
产品
类是
内部
。显然,您不能在任何
public
类型中使用
internal
类(正如编译器所说)。这意味着您将一个类型暴露到一个没有访问该类型的作用域中。在您实现
ipProductRepository
接口的类中,您必须将
Products
属性设置为public。
internal class Product
public interface IProductRepository
{
    IEnumerable<Product> Products { get; }            
}