[英]C# out struct parameter
I have this code in C# but I have a problem whit this code: 我在C#中有此代码,但在此代码中却遇到了问题:
struct myStruct
{
public string sOne;
public string sTwo;
}
public static int ChangeStruct(out myStruct[] arrmyStruct)
{
arrmyStruct= new myStruct[256];
arrSNChildrenStruct[0].sOne= "";
arrSNChildrenStruct[0].sTwo= "";
return 0;
}
But when I build, I have this error: Inconsistent accessibility: parameter type 'out ........ is less accessible than method ..... 但是,当我构建时,出现以下错误:不一致的可访问性:参数类型'out ........比方法.....的访问性差。
What's wrong? 怎么了? Thanks 谢谢
Make a public struct myStruct
instead of internal struct. 将public struct myStruct
而不是内部结构。 Or make ChangeStruct() private
if you only use it locally. 如果仅在本地使用,则将ChangeStruct()设为private
。
This has nothing to do with it being an out
parameter, or an array. 这与out
参数或数组无关。 You'd get the same error with: 您将得到与以下相同的错误:
public static void ChangeStruct(myStruct foo)
Your method is public, but your struct is internal
(the default accessibility for any top-level type) or private
if it's a nested type. 您的方法是公共的,但是您的结构是internal
(任何顶级类型的默认可访问性)或private
如果它是嵌套类型)。 That means that any caller external to your assembly should have access to the method... but can't possibly understand the method signature. 这意味着程序集外部的任何调用者都应该可以访问该方法...但是无法理解方法签名。 C# doesn't allow you to declare methods which refer to types which can't be seen by all possible callers. C#不允许您声明引用所有可能的调用者都看不到的类型的方法。
Options: 选项:
internal
or private
将方法设为internal
或private
Other notes: 其他说明:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.