可访问性不一致:c#中的返回类型 [英] Inconsistent accessibility: return type in c#

查看:92
本文介绍了可访问性不一致:c#中的返回类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了win form application。这个应用程序有2个错误

喜欢



不一致的可访问性:返回类型'System.Collections .Generic.List< pdf_clustering.lib.center>'不如方法'Pdf_Clustering.Lib.FileClustering.prepareCluster(int,System.Collections.Generic.List< pdf_clustering.lib.fileinfo>,ref int)'



另一个错误如



不一致的可访问性:参数类型'System.Collections.Generic.List< pdf_clustering .lib.fileinfo>'不如方法'Pdf_Clustering.Lib.FileClustering.prepareCluster(int,System.Collections.Generic.List< pdf_clustering.lib.fileinfo>,ref int)'



我的代码如下:



中心财产等级:



< pre lang =c#> 使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;

命名空间 Pdf_Clustering.Lib
{
class center
{
public List< Fileinfo> FileGroup { get ; set ; }
}
}





FileClustering如:

 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;

命名空间 Pdf_Clustering.Lib
{
public static class FileClustering
{
private static int Gcounter = 0 ;
private static int counter ;
public static 列表< center> prepareCluster( int k,List< Fileinfo> fCollection, ref int _counter)
{
Cluster_process cp = new Cluster_process();
Gcounter = 0 ;
列表< center> Ccollection = new List< center>();
中心点;

HashSet< int> uniqRand = new HashSet< int>();
Randomnumber_generation( ref uniqRand,k,fCollection.Count);

foreach int pos in uniqRand)
{
point = new center();
point.FileGroup = new List< Fileinfo>();
point.FileGroup.Add(fCollection [pos]);
Ccollection.Add(point);
}

布尔 stopsCriteria;
列表< center> Finalset;
列表< center> BeforeClusterCenter;

InitializeClusterCenter( out Finalset,Ccollection.Count);

do
{
BeforeClusterCenter = Ccollection;

foreach (Fileinfo fi in fCollection)
{

int index = cp.ClosestClusterCenter(Ccollection,fi);
// int index = cp.ClosestClusterCenter(Ccollection,fi);
Finalset [指数] .FileGroup.Add(FI);
}
InitializeClusterCenter( out Ccollection,Ccollection.Count());
Ccollection = cp.Meancalculation(Finalset);
// Ccollection = cp.Meancalculation(Finalset);
stopsCriteria = CheckStoppingCriteria (BeforeClusterCenter,Ccollection);
if (!stopsCriteria)
{

InitializeClusterCenter( out Finalset,Ccollection.Count);
}


} while (stopsCriteria == false );

_counter = counter;
return Finalset;

}





Filinfo property class



 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;

命名空间 Pdf_Clustering.Lib
{
class Fileinfo
{
public long Fsize {获得; set ; }
public string Fname { get ; set ;}
public string Ffullname { get ; set ;}
public string Fextension { get ; set ; }
public string content { get ; set ; }
public float [] Fspace { get ; set ; }
}
}





请帮我解决

解决方案

您的 Fileinfo 类没有定义任何辅助功能;所以它的默认可访问性设置为 internal 。这意味着此类仅可用于定义它的库(或可执行文件)。您不能在外部程序集中使用此类。



因此当您将其设置为 prepareCluster 中的参数时方法,定义为public,编译器警告你,尽管方法是公共的,你将无法从外部程序集中使用它,因为其中一个参数是内部类型,不会可以访问。



解决方案:将您的 Fileinfo 类标记为公开:

< pre lang =c#> public class Fileinfo
{
// ...
}



编译器不应该在此之后抱怨。希望这会有所帮助。


I have develop win form application .this application have 2 errors
like

" Inconsistent accessibility: return type 'System.Collections.Generic.List<pdf_clustering.lib.center>' is less accessible than method 'Pdf_Clustering.Lib.FileClustering.prepareCluster(int, System.Collections.Generic.List<pdf_clustering.lib.fileinfo>, ref int)' "

another error like as

" Inconsistent accessibility: parameter type 'System.Collections.Generic.List<pdf_clustering.lib.fileinfo>' is less accessible than method 'Pdf_Clustering.Lib.FileClustering.prepareCluster(int, System.Collections.Generic.List<pdf_clustering.lib.fileinfo>, ref int)' "

my code like as:

center propert class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Pdf_Clustering.Lib
{
    class center
    {
        public List<Fileinfo> FileGroup { get; set; }
    }
}



FileClustering like as:

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

namespace Pdf_Clustering.Lib
{
   public static class FileClustering
    {
        private static int Gcounter=0;
        private static int counter;
    public static List<center> prepareCluster(int k, List<Fileinfo> fCollection, ref int _counter)
        {
            Cluster_process cp = new Cluster_process();
            Gcounter = 0;
            List<center> Ccollection = new List<center>();
            center point;
       
            HashSet<int> uniqRand = new HashSet<int>();
            Randomnumber_generation(ref uniqRand, k, fCollection.Count);
            
            foreach(int pos in uniqRand) 
            {
                point = new center();
                point.FileGroup = new List<Fileinfo>();
                point.FileGroup.Add(fCollection[pos]);
                Ccollection.Add(point);            
            }

            Boolean stoppingCriteria;
            List<center> Finalset;
            List<center> BeforeClusterCenter;

            InitializeClusterCenter(out Finalset, Ccollection.Count);

            do
            {
                BeforeClusterCenter = Ccollection;

                foreach (Fileinfo fi in fCollection)
                {
                   
                    int index = cp.ClosestClusterCenter(Ccollection, fi);
                    //int index =  cp.ClosestClusterCenter(Ccollection,fi);
                    Finalset[index].FileGroup.Add(fi);
                }
                InitializeClusterCenter(out Ccollection, Ccollection.Count());
                Ccollection = cp.Meancalculation(Finalset);
              //  Ccollection = cp.Meancalculation(Finalset);
                stoppingCriteria = CheckStoppingCriteria(BeforeClusterCenter, Ccollection);
                if (!stoppingCriteria)
                {   
                    
                    InitializeClusterCenter(out Finalset, Ccollection.Count);
                }


            } while (stoppingCriteria == false);

            _counter = counter;
            return Finalset;

        }



Filinfo propert class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Pdf_Clustering.Lib
{
    class Fileinfo
    {
        public long Fsize { get; set; }
        public string Fname { get; set;}
        public string Ffullname { get; set;}
        public string Fextension { get; set; }
        public string content { get; set; }
        public float[] Fspace { get; set; }
    }
}



please help me for solving

解决方案

Your Fileinfo class does not have any accessibility defined ; so its default accessibility is set to internal. That means that this class is usable only from the library (or the executable) that defines it. You cannot use this class from a foreign assembly.

So when you set it as a parameter in the prepareCluster method, which is defined as public, the compiler warns you about the fact that, despite the method being public, you won't be able to use it from a foreign assembly as one of the parameters is of an internal type, which will not be accessible.

Solution : mark your Fileinfo class as public:

public class Fileinfo
{
   //...
}


Compiler should not complain after that. Hope this helps.


这篇关于可访问性不一致:c#中的返回类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆