My visual studio 2010 finds inconsistent accessibility of parameter type error when I compile this C# code:
class Program
{
class BaseClass
{
public class NestedClass
{
}
}
public static bool Function1(BaseClass.NestedClass obj)
{
return true;
}
static void Main(string[] args)
{
Function1(new BaseClass.NestedClass());
new BaseClass.NestedClass();
Console.ReadLine();
}
}
but when I comment function1 it works.
class Program
{
class BaseClass
{
public class NestedClass
{
}
}
//public static bool Function1(BaseClass.NestedClass obj)
//{
// return true;
//}
static void Main(string[] args)
{
//Function1(new BaseClass.NestedClass());
new BaseClass.NestedClass();
Console.ReadLine();
}
}
Why NestedClass can be created but can't be parameter?
EDIT: Sorry, I wasn't quite precise with my question. Above I tried to recreate problem in Console application, but in my project I have other structure of classes:
class BaseClass
{
public class NestedClass
{
}
}
public class OtherClass
{
public void Function1(BaseClass.NestedClass param)
{
var newObj = new BaseClass.NestedClass();
}
}
PS: Setting BaseClass to public really solved my problem. Now, thanks to answers and comments, I understand that it's because public Function1 has greater accessibility than internal (by default) BaseClass. But I don't understand why I can create new NestedClass objects without error?