Newbie question

  • Thread starter Thread starter Robert Dufour
  • Start date Start date
R

Robert Dufour

I am trying to understand what the following code does. More specifically
after the :base word
I understand that it Creates an Object MembershipUserWrapper to which a
parameter of type MembershipUser that will be named mu in the function is
passed.
The : base means that it creates a new object derived from the base class
which is a system.web.security.membership object
My question is with the mu.ProviderName and following parameters.
What does it DO? does it assign the provider name of the passed mu to the
new base or does it apply the value of the new base class to the
corresponding mu property?

Code below
Thanks for any help
Bob


/// This constructor is used to create a MembershipUserWrapper
/// from a MembershipUser object.

/// MembershipUser is a default type used

/// in the Membership API provided with ASP.NET 2.0

/// </summary>

/// <param name="mu">MembershipUser object</param>

public MembershipUserWrapper(MembershipUser mu)

: base(mu.ProviderName, mu.UserName, mu.ProviderUserKey, mu.Email,
mu.PasswordQuestion,

mu.Comment, mu.IsApproved, mu.IsLockedOut, mu.CreationDate,
mu.LastLoginDate, mu.LastActivityDate,

mu.LastPasswordChangedDate, mu.LastLockoutDate)

{

}
 
Robert Dufour said:
I am trying to understand what the following code does. More specifically
after the :base word
I understand that it Creates an Object MembershipUserWrapper to which a
parameter of type MembershipUser that will be named mu in the function is
passed.
The : base means that it creates a new object derived from the base class
which is a system.web.security.membership object
My question is with the mu.ProviderName and following parameters.
What does it DO? does it assign the provider name of the passed mu to the
new base or does it apply the value of the new base class to the
corresponding mu property?

It calls the base class constructor. See
http://pobox.com/~skeet/csharp/constructors.html
 
Bob,

You are confusing the syntax for calling the base class constructor with
the syntax for inheriting from a base class.

The code below illustrates. In this simple case foo calls the same
constructor in bar, but it could be some other constructor in bar with
different arguments, which is what you're seeing in the constructor code
you showed.

class foo : bar {

foo(someArg,someOtherArg) : base(someArg,someOtherArg) {
// after calling bar's constructor, do some additional
// stuff specific to foo
}

}

Two implications that bothered me when I was new to C#:

1) If you call the base constructor, you have to do it first. You can't
do it last, or in the middle of foo's constructor. In practice, I
haven't found this lack of flexibility to be a practical problem, however.

2) Class inheritance does not extend to constructors (other than a
default parameterless constructor) unless you explicitly wire it up like
this. This I *have* found to be a minor annoyance.

--Bob (a different one)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top