|
-
Jun 15th, 2007, 06:21 AM
#1
Thread Starter
Lively Member
[RESOLVED] [2.0] keyword 'PUBLIC' in a constructor ?
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......
-
Jun 15th, 2007, 06:38 AM
#2
Re: [2.0] keyword 'PUBLIC' in a constructor ?
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.
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jun 15th, 2007, 06:53 AM
#3
Thread Starter
Lively Member
Re: [2.0] keyword 'PUBLIC' in a constructor ?
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
-
Jun 15th, 2007, 08:04 AM
#4
Re: [RESOLVED] [2.0] keyword 'PUBLIC' in a constructor ?
Take a look at MSDN articles about Access Modifiers and about constructors
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jun 16th, 2007, 09:54 AM
#5
Re: [RESOLVED] [2.0] keyword 'PUBLIC' in a constructor ?
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|