overriding inheritted methods syntax


T

TS

i have a class that i'm trying to understand that overrides
BaseApplicationException's methods as follows. What i dont' understand is
that i have never seen the inherit ":" on a method signature, only on a
class declaration.

Can you explain what is going on here. Is it that the implementation of the
method that is overriding the base's method simply uses the base's
implementation all along (if so, why override the method to begin with?)?

[Serializable()]
public sealed class BusinessException : BaseApplicationException,
ISerializable
{
/// <summary>
/// Initializes a new instance of the <see cref="BusinessException"/>
class.
/// </summary>
public BusinessException() : base()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="BusinessException"/>
class with a specified error message.
/// </summary>
/// <param name="message">The error message that explains the reason for
the exception.</param>
public BusinessException(string message) : base(message)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="BusinessException"/>
class with a specified
/// error message and a reference to the inner exception that is the cause
of this exception.
/// </summary>
/// <param name="message">The error message that explains the reason for
the exception.</param>
/// <param name="innerException">
/// The exception that is the cause of the current exception. If the
<paramref name="innerException" /> parameter is not a
/// null reference, the current exception is raised in a <c>catch</c>
block that handles the inner exception.
/// </param>
public BusinessException(string message, Exception innerException) :
base(message, innerException)
{
}
}
 
Ad

Advertisements

J

Jonathan Allen

public BusinessException() : base()

That should call the base-class constructor before running your constructor
code.
 
B

Bruce Wood

You will see this notation only on constructors. There are only two
valid forms:

public MyClass(string myParam1, int myParam2) : base(myParam1)
{ ... }

and

public MyClass(int myParam3) : this(null, myParam3)
{ ... }

In the first case, you are saying, "Before you run my cnstructor code,
run the constructor for my base class and pass it the string myParam1."
In the second case, you are saying "Before you run my constructor code,
run the other constructor for this same class and pass it a null and
the int myParam3."
 
J

Jon Skeet [C# MVP]

TS said:
i have a class that i'm trying to understand that overrides
BaseApplicationException's methods as follows. What i dont' understand is
that i have never seen the inherit ":" on a method signature, only on a
class declaration.

Can you explain what is going on here. Is it that the implementation of the
method that is overriding the base's method simply uses the base's
implementation all along (if so, why override the method to begin with?)?

See http://www.pobox.com/~skeet/csharp/constructors.html

Note that no overriding is going on here, as constructors aren't
inherited. Instead, constructors are being provided which call the
appropriate base class constructors.
 
Ad

Advertisements


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

Top