overriding inheritted methods syntax

  • Thread starter Thread starter TS
  • Start date Start date
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)
{
}
}
 
public BusinessException() : base()

That should call the base-class constructor before running your constructor
code.
 
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."
 
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.
 
Back
Top