Hi, just started C# today using VS2005. I seem to need to use the PUBLIC keyword when making constructors for classes. If I don't then I get the error that the constructor is inaccessable !!! But the class is public...... :confused:
Printable View
Hi, just started C# today using VS2005. I seem to need to use the PUBLIC keyword when making constructors for classes. If I don't then I get the error that the constructor is inaccessable !!! But the class is public...... :confused:
The class is public, this means you have access to the class itself, or any public members within.
You need to have at least one public constructor in order to create an instance of the class.
oh, and it's public... C# is case sensitive.
thanks , I will accept that for now. I have seen constructors without the public keyword. I figured a constructor wouldn't need it.
Anyway your help was very appreciated :wave:
Take a look at MSDN articles about Access Modifiers and about constructors
Just like any member a constructor can be public, private or internal. Just like any other member a class constructor is private by default, so if you want it to be internal or public you must explicitly specify it. Constructors are no different to any other members except that they are invoked implicitly using the 'new' key word rather than explicitly.