Class Initialization

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shapper

    Class Initialization

    Hello,

    I have a class as follows:

    public class UserPaper {
    public MembershipUser user { get; set; }
    public string Password { get; set; }

    public UserLeaf(Member shipUser newUser) {
    UserLeaf(newUse r, null);
    }
    public UserLeaf(Member shipUser newUser, string password) {
    this user = newUser;
    this password = password;
    }
    }

    I simplified my code but basically I get the following error:
    'UserPaper' is a 'type' but is used like a 'variable'

    Do I need to repeat the definition in all methods? I am a little bit
    confused.

    Thanks,
    Miguel
  • Martin Honnen

    #2
    Re: Class Initialization

    shapper wrote:
    Hello,
    >
    I have a class as follows:
    >
    public class UserPaper {
    public MembershipUser user { get; set; }
    public string Password { get; set; }
    >
    public UserLeaf(Member shipUser newUser) {
    UserLeaf(newUse r, null);
    }
    public UserLeaf(Member shipUser newUser, string password) {
    this user = newUser;
    this password = password;
    }
    }
    >
    I simplified my code but basically I get the following error:
    'UserPaper' is a 'type' but is used like a 'variable'
    >
    Do I need to repeat the definition in all methods? I am a little bit
    confused.
    I think you want the following:

    public class UserPaper {
    public MembershipUser User { get; set; }
    public string Password { get; set; }

    public UserPaper(Membe rshipUser newUser): this(newUser, null){

    }
    public UserPaper(Membe rshipUser newUser, string newPassword) {
    User = newUser;
    Password = newPassword;
    }
    }



    --

    Martin Honnen --- MVP XML

    Comment

    • Clive Dixon

      #3
      Re: Class Initialization

      Your class is called "UserPaper" but there are constructor-like members
      called "UserLeaf". Constructors must have the same name as the class.

      Secondly, you need to chain the first constructor onto the second as
      follows:

      public class UserPaper
      {
      // snip

      public UserPaper(Membe rshipUser newUser) : this(newUser, null)
      {
      }

      public UserPaper(Membe rshipUser newUser, string password)
      {
      this.user = newUser;
      this.password = password;
      }
      }


      "shapper" <mdmoura@gmail. comwrote in message
      news:6c136aaa-783b-4e48-85c6-69f1920b199e@40 g2000prx.google groups.com...
      Hello,
      >
      I have a class as follows:
      >
      public class UserPaper {
      public MembershipUser user { get; set; }
      public string Password { get; set; }
      >
      public UserLeaf(Member shipUser newUser) {
      UserLeaf(newUse r, null);
      }
      public UserLeaf(Member shipUser newUser, string password) {
      this user = newUser;
      this password = password;
      }
      }
      >
      I simplified my code but basically I get the following error:
      'UserPaper' is a 'type' but is used like a 'variable'
      >
      Do I need to repeat the definition in all methods? I am a little bit
      confused.
      >
      Thanks,
      Miguel

      Comment

      • shapper

        #4
        Re: Class Initialization

        On Oct 31, 2:44 pm, "Clive Dixon" <clived at digita dot comwrote:
        Your class is called "UserPaper" but there are constructor-like members
        called "UserLeaf". Constructors must have the same name as the class.
        >
        Secondly, you need to chain the first constructor onto the second as
        follows:
        >
        public class UserPaper
        {
            // snip
        >
            public UserPaper(Membe rshipUser newUser) : this(newUser, null)
            {
            }
        >
            public UserPaper(Membe rshipUser newUser, string password)
            {
              this.user = newUser;
              this.password = password;
            }
        >
        }
        "shapper" <mdmo...@gmail. comwrote in message
        >
        news:6c136aaa-783b-4e48-85c6-69f1920b199e@40 g2000prx.google groups.com...
        >
        Hello,
        >
        I have a class as follows:
        >
         public class UserPaper {
           public MembershipUser user { get; set; }
           public string Password { get; set; }
        >
           public UserLeaf(Member shipUser newUser) {
             UserLeaf(newUse r, null);
           }
           public UserLeaf(Member shipUser newUser, string password) {
             this user = newUser;
             this password = password;
           }
        }
        >
        I simplified my code but basically I get the following error:
        'UserPaper' is a 'type' but is used like a 'variable'
        >
        Do I need to repeat the definition in all methods? I am a little bit
        confused.
        >
        Thanks,
        Miguel
        The UserPaper and UserLeaf was a mistake when copying the code here.
        For sake of simplicity I didn't copy paste the entire code and I wrote
        it wrong.

        But yes your answers were what I was looking for.

        Thank You!
        Miguel

        Comment

        Working...