Constructor

S

shapper

Hello,

I have the following class:

public class PagedList<T> : List<T>, IPagedList<T> {

public PagedList(IEnumerable<T> source, Int32 index, Int32 size)
{
// Some code
} // PagedList

public PagedList(IQueryable<T> source, Int32 index, Int32 size) {
PagedList(source.AsEnumerable(), index, size);
}

}

I get the error:
Using the generic type 'PagedList<T>' requires '1' type arguments

I understand that it is asking me the T but what I am trying is to
call the other constructor.
This might be strange but basically I am trying to initialize a class
in two different ways but since IQueryable implements IEnumerable then
the code will be the same same ...

Thanks,
Miguel
 
A

Alberto Poblacion

shapper said:
public class PagedList<T> : List<T>, IPagedList<T> {

public PagedList(IEnumerable<T> source, Int32 index, Int32 size)
{
// Some code
} // PagedList

public PagedList(IQueryable<T> source, Int32 index, Int32 size) {
PagedList(source.AsEnumerable(), index, size);
}

}

I get the error:
Using the generic type 'PagedList<T>' requires '1' type arguments

I understand that it is asking me the T but what I am trying is to
call the other constructor.

You cannot call another constructor in the same way as if it was a
method. Instead you use a syntax that uses a colon and is known as an
"Initializer List":

public PagedList(IQueryable<T> source, Int32 index, Int32 size) :
PagedList(source.AsEnumerable(), index, size)
{
}
 
A

Alberto Poblacion

Alberto Poblacion said:
You cannot call another constructor in the same way as if it was a
method. Instead you use a syntax that uses a colon and is known as an
"Initializer List":

public PagedList(IQueryable<T> source, Int32 index, Int32 size) :
PagedList(source.AsEnumerable(), index, size)
{
}

Sorry, I copied and pasted and forgot to edit the pasted text. Should be
"this" instead of "PagedList":

public PagedList(IQueryable<T> source, Int32 index, Int32 size) :
this(source.AsEnumerable(), index, size)
{
}
 
S

shapper

    Sorry, I copied and pasted and forgot to edit the pasted text. Should be
"this" instead of "PagedList":

 public PagedList(IQueryable<T> source, Int32 index, Int32 size) :
     this(source.AsEnumerable(), index, size)
     {
     }

My error. I did that before but I was calling the IQueryable
constructor from the IEnumerable constructor and I think that was the
problem ...
.... Or something else ...

Anyway:
Thanks!
Miguel
 

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