我正在尝试在两个表单之间传递一个对象(基本上是对当前登录用户的引用)。目前,我在登录表单中有这些内容:
private ACTInterface oActInterface;
public void button1_Click(object sender, EventArgs e)
{
oActInterface = new ACTInterface(@"\\actserver\Database\Premier.pad",this.textUser.Text,this.textPass.Text);
if (oActInterface.checkLoggedIn())
{
//user has authed against ACT, so we can carry on
clients oClientForm = new clients(oActInterface);
this.Hide();
oClientForm.Show();
}
else...
在下一个表格(客户)上,我有:
public partial class clients : Form
{
private ACTInterface oActInt {get; set;}
public clients(ACTInterface _oActInt)
...这导致我得到:
Error 1 Inconsistent accessibility:
parameter type 'support.ACTInterface' is less accessible than method
'support.clients.clients(support.ACTInterface)'
c:\work\net\backup\support\support\clients.cs 20 16 support
我真的不明白问题是什么 - 两个字段都是私有的,并且可以通过表单中的相关公共方法访问。谷歌搜索并没有真正帮助,因为它只是指向一个元素是公共的而另一个是私有的,这不是这里的情况。
有人帮忙吗?
答案 0 :(得分:286)
public
类clients
的构造函数是public
,但它的ACTInterface
类型的参数是private
(它嵌套在类中?) 。你不能这样做。您需要ACTInterface
至少与clients
一样方便。
答案 1 :(得分:61)
让课程公开。
class NewClass
{
}
与:
相同internal class NewClass
{
}
因此课程必须是公开的
答案 2 :(得分:25)
如果ACTInterface
类型的声音不是public
,而是使用internal
(如果是顶级)或private
的默认辅助功能(如果它嵌套在另一种类型中。)
赋予public
修饰符类型可以修复它。
另一种方法是同时制作类型和方法internal
,如果这是你的意图。
问题不在于字段(oActInterface
)的可访问性,而在于ACTInterface
本身的类型。
答案 3 :(得分:8)
support.ACTInterface
类型的可访问性是什么?该错误表明它不公开。
如果签名的某些参数类型不公开,则不能公开公共方法签名。由于调用者无法构造所需的参数,因此无法从外部调用该方法。
如果您公开support.ACTInterface
将删除此错误。或者,如果可能,请减少表单方法的可访问性。
答案 4 :(得分:4)
问题似乎不是变量,而是ACTInterface的声明。 ACTInterface是否有机会被宣布为内部?
答案 5 :(得分:4)
parameter type 'support.ACTInterface' is less accessible than method
'support.clients.clients(support.ACTInterface)'
错误提示'support.ACTInterface'难以访问,因为您已将接口设为私有接口,至少将其设为内部或公开。
答案 6 :(得分:2)
当我收到此错误时,我有一个"帮助"我没有声明为公开的类,在使用" helper"的类中引起了这个问题。类。制作"帮助" class public解决了这个错误,如:
public ServiceClass { public ServiceClass(HelperClass _helper) {} }
public class HelperClass {} //注意解决了我的问题的公共HelperClass。
这可能有助于遇到此事的其他人。
答案 7 :(得分:0)
如果要在新表单中使用类变量时发生此错误,则应将类定义放在
中Formname.Designer.cs
而不是Formname.cs文件。
答案 8 :(得分:0)
更新我的实体框架模型后,我发现此错误会影响我的解决方案中的多个文件。我只需右键单击我的.edmx文件和我的TT文件,然后单击“运行自定义工具”,重新启动Visual Studio 2012后,我就再次使用了。
答案 9 :(得分:0)
您可以使用object
来获取Parameter(可访问性较低的类),然后通过as
关键字将其转换为您的类。
答案 10 :(得分:-3)
尝试将构造函数设为私有,如下所示:
private Foo newClass = new Foo();