Search
[C#] Inconsistent accessibility
- M.R

- Oct 18, 2021
- 1 min read
Phenomenon
In C #, the following code causes a title compilation error.
This error occurs when, for example, the class is private but the method is public, but in this example both are public.
public class MyClass{
public MyClass(OtherClass data){ //error here
//omit
}Cause and Solution
The constructor argument OtherClass was private.
When I changed this to public, the compile error disappeared.
It was a trivial error, but it was a blind spot because I was only concerned about the accessibility of class and method.







Comments