Re: Constructor in sublass of List<>

Tech-Archive recommends: Fix windows errors by optimizing your registry




"PJ" <pjwal@xxxxxxxxxxx> wrote in message
news:vdudnbR1cP332VXeRVn-uA@xxxxxxxxxxxxxxxx
>I have a class definition :
>
> public class PagingList<T> : List<T>
> {
> private int pageSize, pageNumber;
> public PagingList()
> {
> pageSize = (this.Count == 0) ? 1 : this.Count;
> pageNumber = 1;
> }
>
>
> My problem is that this.Count is 0, apparently the list items aren't
> available in the constructor. Is it possible to get access to the list
> items in the constructor?
>
>

No the object isn't constructed yet so it can't have had items added to it
already.

But you can add a parameter to the constructor.
EG:

public class PagingList<T> : List<T>
{
private int pageSize, pageNumber;
public PagingList(int pageSize)
{
this.pageSize = pageSize;
this.pageNumber = 1;
}

David


.



Relevant Pages

  • Re: Constructor in sublass of List<>
    ... > private int pageSize, pageNumber; ... > My problem is that this.Count is 0, apparently the list items aren't ... > available in the constructor. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Constructor in sublass of List<>
    ... | private int pageSize, pageNumber; ... | available in the constructor. ... Joanna Carter ...
    (microsoft.public.dotnet.languages.csharp)
  • Constructor in sublass of List<>
    ... private int pageSize, pageNumber; ... My problem is that this.Count is 0, apparently the list items aren't ... available in the constructor. ...
    (microsoft.public.dotnet.languages.csharp)