Results 1 to 5 of 5

Thread: [RESOLVED] [2.0] keyword 'PUBLIC' in a constructor ?

  1. #1

    Thread Starter
    Lively Member mikelynch's Avatar
    Join Date
    May 2006
    Location
    Goombungee Qld
    Posts
    83

    Resolved [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......

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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

  3. #3

    Thread Starter
    Lively Member mikelynch's Avatar
    Join Date
    May 2006
    Location
    Goombungee Qld
    Posts
    83

    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

  4. #4
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width