我试图在两个表单之间传递一个对象(基本上是对当前登录用户的引用).目前,我在登录表单中有这些内容:
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...
Run Code Online (Sandbox Code Playgroud)
在下一个表格(客户)上,我有:
public partial class clients : Form
{
private ACTInterface oActInt {get; set;}
public clients(ACTInterface _oActInt)
Run Code Online (Sandbox Code Playgroud)
...导致我得到:
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
Run Code Online (Sandbox Code Playgroud)
我真的不明白问题是什么 - 两个字段都是私有的,并且可以通过表单中的相关公共方法访问.谷歌搜索并没有真正帮助,因为它只是指向一个元素是公共的而另一个是私有的,这不是这里的情况.
有人帮忙吗?
jas*_*son 312
的构造public类clients是public但它有类型的参数ACTInterface是private(它嵌套在一个类?).你不能这样做.你ACTInterface至少要像以下那样使用clients.
Nis*_*sha 68
让课程公开.
class NewClass
{
}
Run Code Online (Sandbox Code Playgroud)
是相同的:
internal class NewClass
{
}
Run Code Online (Sandbox Code Playgroud)
所以上课必须公开
Mar*_*ell 27
如果声音类型ACTInterface不是public,但使用默认的可访问性internal(如果它是顶级)或private(如果它嵌套在另一种类型).
赋予public修饰符类型可以修复它.
另一种方法是同时制作类型和方法internal,如果这是你的意图.
问题不在于field(oActInterface)的可访问性,而在于类型ACTInterface本身.
该类型的可访问性是什么support.ACTInterface.该错误表明它不公开.
如果签名的某些参数类型不公开,则不能公开公共方法签名.由于调用者无法构造所需的参数,因此无法从外部调用该方法.
如果您support.ACTInterface公开将删除此错误.或者,如果可能,减少表单方法的可访问性.
parameter type 'support.ACTInterface' is less accessible than method
'support.clients.clients(support.ACTInterface)'
Run Code Online (Sandbox Code Playgroud)
错误说“support.ACTInterface”不太容易访问,因为您已将接口设为私有,至少将其设为内部或公开。
小智 5
当我收到此错误时,我有一个“helper”类,但我没有将其声明为公共,这导致使用“helper”类的类内部出现此问题。将“helper”类公开解决了这个错误,如下所示:
公共 ServiceClass { 公共 ServiceClass(HelperClass _helper) { } }
public class HelperClass {} // 请注意解决了我的问题的 public HelperClass。
这可能会帮助其他遇到这种情况的人。