0

I have this code in C# but I have a problem whit this code:

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 .....

What's wrong? Thanks

2
  • 4
    make myStruct public, it is internal by default Commented Jun 27, 2014 at 10:59
  • When don't specify any access specefier it takes Internal as default. Hence to make it public write it like.. public struct myStruct Commented Jun 27, 2014 at 11:00

2 Answers 2

7

Make a public struct myStruct instead of internal struct. Or make ChangeStruct() private if you only use it locally.

Sign up to request clarification or add additional context in comments.

Comments

5

This has nothing to do with it being an out parameter, or an array. 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. 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.

Options:

  • Make the method internal or private
  • Make the struct public

Other notes:

  • Your naming is very unconventional. Name your types according to their meaning, and make it PascalCased. Drop the "arr" prefix from your variable names.
  • Public fields are usually a bad idea, as are mutable structs.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.