overriding inheritted methods syntax

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

    overriding inheritted methods syntax

    i have a class that i'm trying to understand that overrides
    BaseApplication Exception'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 BusinessExcepti on : BaseApplication Exception,
    ISerializable
    {
    /// <summary>
    /// Initializes a new instance of the <see cref="BusinessE xception"/>
    class.
    /// </summary>
    public BusinessExcepti on() : base()
    {
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="BusinessE xception"/>
    class with a specified error message.
    /// </summary>
    /// <param name="message"> The error message that explains the reason for
    the exception.</param>
    public BusinessExcepti on(string message) : base(message)
    {
    }
    /// <summary>
    /// Initializes a new instance of the <see cref="BusinessE xception"/>
    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="innerExce ption">
    /// The exception that is the cause of the current exception. If the
    <paramref name="innerExce ption" /> parameter is not a
    /// null reference, the current exception is raised in a <c>catch</c>
    block that handles the inner exception.
    /// </param>
    public BusinessExcepti on(string message, Exception innerException) :
    base(message, innerException)
    {
    }
    }


  • Jonathan Allen

    #2
    Re: overriding inheritted methods syntax

    > public BusinessExcepti on() : base()

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

    --
    Jonathan Allen


    "TS" <manofsteele1@n ospam.nospam> wrote in message
    news:e62E1OuaFH A.2496@TK2MSFTN GP14.phx.gbl...[color=blue]
    >i have a class that i'm trying to understand that overrides
    > BaseApplication Exception'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 BusinessExcepti on : BaseApplication Exception,
    > ISerializable
    > {
    > /// <summary>
    > /// Initializes a new instance of the <see cref="BusinessE xception"/>
    > class.
    > /// </summary>
    > public BusinessExcepti on() : base()
    > {
    > }
    >
    > /// <summary>
    > /// Initializes a new instance of the <see cref="BusinessE xception"/>
    > class with a specified error message.
    > /// </summary>
    > /// <param name="message"> The error message that explains the reason for
    > the exception.</param>
    > public BusinessExcepti on(string message) : base(message)
    > {
    > }
    > /// <summary>
    > /// Initializes a new instance of the <see cref="BusinessE xception"/>
    > 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="innerExce ption">
    > /// The exception that is the cause of the current exception. If the
    > <paramref name="innerExce ption" /> parameter is not a
    > /// null reference, the current exception is raised in a <c>catch</c>
    > block that handles the inner exception.
    > /// </param>
    > public BusinessExcepti on(string message, Exception innerException) :
    > base(message, innerException)
    > {
    > }
    > }
    >
    >[/color]


    Comment

    • Bruce Wood

      #3
      Re: overriding inheritted methods syntax

      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."

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: overriding inheritted methods syntax

        TS <manofsteele1@n ospam.nospam> wrote:[color=blue]
        > i have a class that i'm trying to understand that overrides
        > BaseApplication Exception'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?)?[/color]

        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.

        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        • TS

          #5
          Re: overriding inheritted methods syntax

          thanks all who contributed, i now understand


          "TS" <manofsteele1@n ospam.nospam> wrote in message
          news:e62E1OuaFH A.2496@TK2MSFTN GP14.phx.gbl...[color=blue]
          > i have a class that i'm trying to understand that overrides
          > BaseApplication Exception'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[/color]
          the[color=blue]
          > 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 BusinessExcepti on : BaseApplication Exception,
          > ISerializable
          > {
          > /// <summary>
          > /// Initializes a new instance of the <see cref="BusinessE xception"/>
          > class.
          > /// </summary>
          > public BusinessExcepti on() : base()
          > {
          > }
          >
          > /// <summary>
          > /// Initializes a new instance of the <see cref="BusinessE xception"/>
          > class with a specified error message.
          > /// </summary>
          > /// <param name="message"> The error message that explains the reason for
          > the exception.</param>
          > public BusinessExcepti on(string message) : base(message)
          > {
          > }
          > /// <summary>
          > /// Initializes a new instance of the <see cref="BusinessE xception"/>
          > class with a specified
          > /// error message and a reference to the inner exception that is the[/color]
          cause[color=blue]
          > of this exception.
          > /// </summary>
          > /// <param name="message"> The error message that explains the reason for
          > the exception.</param>
          > /// <param name="innerExce ption">
          > /// The exception that is the cause of the current exception. If the
          > <paramref name="innerExce ption" /> parameter is not a
          > /// null reference, the current exception is raised in a <c>catch</c>
          > block that handles the inner exception.
          > /// </param>
          > public BusinessExcepti on(string message, Exception innerException) :
          > base(message, innerException)
          > {
          > }
          > }
          >
          >[/color]


          Comment

          Working...