PC Review


Reply
Thread Tools Rate Thread

Class Initialization

 
 
shapper
Guest
Posts: n/a
 
      31st Oct 2008
Hello,

I have a class as follows:

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

public UserLeaf(MembershipUser newUser) {
UserLeaf(newUser, null);
}
public UserLeaf(MembershipUser 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
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      31st Oct 2008
shapper wrote:
> Hello,
>
> I have a class as follows:
>
> public class UserPaper {
> public MembershipUser user { get; set; }
> public string Password { get; set; }
>
> public UserLeaf(MembershipUser newUser) {
> UserLeaf(newUser, null);
> }
> public UserLeaf(MembershipUser 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(MembershipUser newUser): this(newUser, null){

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



--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
Clive Dixon
Guest
Posts: n/a
 
      31st Oct 2008
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(MembershipUser newUser) : this(newUser, null)
{
}

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


"shapper" <(E-Mail Removed)> wrote in message
news:6c136aaa-783b-4e48-85c6-(E-Mail Removed)...
> Hello,
>
> I have a class as follows:
>
> public class UserPaper {
> public MembershipUser user { get; set; }
> public string Password { get; set; }
>
> public UserLeaf(MembershipUser newUser) {
> UserLeaf(newUser, null);
> }
> public UserLeaf(MembershipUser 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



 
Reply With Quote
 
shapper
Guest
Posts: n/a
 
      31st Oct 2008
On Oct 31, 2:44*pm, "Clive Dixon" <clived at digita dot com> wrote:
> 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(MembershipUser newUser) : this(newUser, null)
> * * {
> * * }
>
> * * public UserPaper(MembershipUser newUser, string password)
> * * {
> * * * this.user = newUser;
> * * * this.password = password;
> * * }
>
> }
> "shapper" <mdmo...@gmail.com> wrote in message
>
> news:6c136aaa-783b-4e48-85c6-(E-Mail Removed)...
>
> > Hello,

>
> > I have a class as follows:

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

>
> > * *public UserLeaf(MembershipUser newUser) {
> > * * *UserLeaf(newUser, null);
> > * *}
> > * *public UserLeaf(MembershipUser 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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array initialization in class =?Utf-8?B?Z29s?= Microsoft Dot NET Framework Forms 10 25th Sep 2007 06:44 AM
Class modules Custom initialization Line =?Utf-8?B?SiBTdHJlZ2Vy?= Microsoft Excel Programming 2 28th Jun 2007 01:56 PM
Initialization of static variables in a class library Jesper Schmidt Microsoft VC .NET 5 23rd Oct 2006 01:08 PM
class member initialization Boni Microsoft C# .NET 6 4th Oct 2005 11:01 AM
Terminating application during class initialization Wysiwyg Microsoft C# .NET 2 29th Apr 2005 08:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:18 AM.