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

S

SammyBar

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
 
N

Nicholas Paldino [.NET/C# MVP]

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

Michael Bray

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?

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

-mdb
 

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