default constructor C# private or public?
Default constructor for C#, if it is not specificed, is private.
you can test it via
public class TestConstructor
{
public string title2 = string.Empty;
string title = string.Empty;
}
you will found that when you
TestConstructor tc = new TestConstructor();
tc.title2 ==> this is valid in the intellisence
tc.title ==> TestConstructor.title' is inaccessible due to its protection level
tc.somethingNotExist ==> TestConstructor does not contain a definition for 'somethingNotExist' and no extension method 'somethingNotExist' accepting a first argument of type 'TestConstructor' could be found (are you missing a using directive or an assembly reference?)
No comments:
Post a Comment