Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Error 1 'character': member names cannot be the same as their enclosing type

Error 1 'character': member names cannot be the same as their enclosing type

Scheduled Pinned Locked Moved C#
helpcsharpc++question
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    msheekhah
    wrote on last edited by
    #1

    i'm teaching myself c#. i got through polymophism, pointers, linked lists, and data structures in C++ in college decades ago. however, I'm spacing on the easy shit it seems. Can someone help me out?

    using System;
    ...
    using System.Windows.Forms;

    namespace WindowsFormsApplication4
    {
    ...

    public class character
    {
    protected Hashtable charSheet = new Hashtable();
    protected Hashtable mutantStats = new Hashtable();
    protected Hashtable mutantPower = new Hashtable();

            public void character()
            {
                charSheet.Add("Name", "");
                ...
                mutantStats.Add("Tactics", "");
            }
            public void character(string nm,int xp,int lvl,int str,int dex,int sta,int spe,int hea,int soa,int def)
            {
                charSheet.Add("Name", nm);
                ...
                mutantStats.Add("Defense", "");
            }
            
            // constructors
    
          ...
    
    P H 2 Replies Last reply
    0
    • M msheekhah

      i'm teaching myself c#. i got through polymophism, pointers, linked lists, and data structures in C++ in college decades ago. however, I'm spacing on the easy shit it seems. Can someone help me out?

      using System;
      ...
      using System.Windows.Forms;

      namespace WindowsFormsApplication4
      {
      ...

      public class character
      {
      protected Hashtable charSheet = new Hashtable();
      protected Hashtable mutantStats = new Hashtable();
      protected Hashtable mutantPower = new Hashtable();

              public void character()
              {
                  charSheet.Add("Name", "");
                  ...
                  mutantStats.Add("Tactics", "");
              }
              public void character(string nm,int xp,int lvl,int str,int dex,int sta,int spe,int hea,int soa,int def)
              {
                  charSheet.Add("Name", nm);
                  ...
                  mutantStats.Add("Defense", "");
              }
              
              // constructors
      
            ...
      
      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      The error does tell you what it the problem is. Basically, you can't have a method name that's exactly the same as the class name. BTW - if you're using .NET 2 (or later), you have better options than Hashtable available to you. You may want to use the generic Dictionary class.

      "WPF has many lovers. It's a veritable porn star!" - Josh Smith

      As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

      My blog | My articles | MoXAML PowerToys | Onyx

      1 Reply Last reply
      0
      • M msheekhah

        i'm teaching myself c#. i got through polymophism, pointers, linked lists, and data structures in C++ in college decades ago. however, I'm spacing on the easy shit it seems. Can someone help me out?

        using System;
        ...
        using System.Windows.Forms;

        namespace WindowsFormsApplication4
        {
        ...

        public class character
        {
        protected Hashtable charSheet = new Hashtable();
        protected Hashtable mutantStats = new Hashtable();
        protected Hashtable mutantPower = new Hashtable();

                public void character()
                {
                    charSheet.Add("Name", "");
                    ...
                    mutantStats.Add("Tactics", "");
                }
                public void character(string nm,int xp,int lvl,int str,int dex,int sta,int spe,int hea,int soa,int def)
                {
                    charSheet.Add("Name", nm);
                    ...
                    mutantStats.Add("Defense", "");
                }
                
                // constructors
        
              ...
        
        H Offline
        H Offline
        Henry Minute
        wrote on last edited by
        #3

        If public void character() and public void character(string nm,int xp,int lvl,int str,int dex,int sta,int spe,int hea,int soa,int def), are meant to be constructors remove the void. Leaving just public character(...... Constructors do not have a return type. :)

        Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

        M 1 Reply Last reply
        0
        • H Henry Minute

          If public void character() and public void character(string nm,int xp,int lvl,int str,int dex,int sta,int spe,int hea,int soa,int def), are meant to be constructors remove the void. Leaving just public character(...... Constructors do not have a return type. :)

          Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

          M Offline
          M Offline
          msheekhah
          wrote on last edited by
          #4

          yeah fixed. thanks. getting better at getting bugs fixed using MSDN search. hopefully keep the stupid shit to a minimum.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups