Calling base class default constructor when the base is a generic...

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

    #1

    Calling base class default constructor when the base is a generic...

    I'm trying to inherit from a Generic class but I'm having troubles on the
    syntax on how to specify a base constructor for my default constructor. I
    want to do something like this:

    public class NombreValorList : Dictionary<int, String>
    {
    public NombreValorList () : Dictionary<int, String>()
    {
    }
    }

    But the compiler wants the "base" keyword included.

    Which is the correct syntax in this case?

    Thanks in advance

    Sammy



  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Calling base class default constructor when the base is a generic...

    Sammy,

    Well, I don't think that you have a choice. If the compiler wants the
    "base" keyword, then it's going to get it. It's not going to output IL any
    other way. =)

    To that end, you need to do:

    public class NombreValorList : Dictionary<int, String>
    {
    public NombreValorList () : base()
    {
    }
    }

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "SammyBar" <sammybar@gmail .com> wrote in message
    news:O3anzesGGH A.3728@tk2msftn gp13.phx.gbl...[color=blue]
    > I'm trying to inherit from a Generic class but I'm having troubles on the
    > syntax on how to specify a base constructor for my default constructor. I
    > want to do something like this:
    >
    > public class NombreValorList : Dictionary<int, String>
    > {
    > public NombreValorList () : Dictionary<int, String>()
    > {
    > }
    > }
    >
    > But the compiler wants the "base" keyword included.
    >
    > Which is the correct syntax in this case?
    >
    > Thanks in advance
    >
    > Sammy
    >
    >
    >[/color]


    Comment

    • Michael Bray

      #3
      Re: Calling base class default constructor when the base is a generic...

      "SammyBar" <sammybar@gmail .com> wrote in news:O3anzesGGH A.3728
      @tk2msftngp13.p hx.gbl:
      [color=blue]
      > public class NombreValorList : Dictionary<int, String>
      > {
      > public NombreValorList () : Dictionary<int, String>()
      > {
      > }
      > }
      >
      > But the compiler wants the "base" keyword included.
      >
      > Which is the correct syntax in this case?
      >[/color]

      public NombreValorList () : base()
      {
      ....
      }

      -mdb

      Comment

      • SammyBar

        #4
        Re: Calling base class default constructor when the base is a generic...

        > public NombreValorList () : base()[color=blue]
        > {
        > }[/color]

        Yes! It is evident... Sorry for your time and thanks a lot!
        Sammy


        Comment

        Working...