1
public class PaginationHelper<T> : IPagination<T>
{
public int PageNumber { get; set; }
public int PageSize { get; set; }
public IList<T> Items { get; set; }
public IList<T> PaginationItems => AsPagination();
public int TotalItems { get; set; }
public int FirstItem => (PageNumber - 1) * PageSize + 1;
public int LastItem => FirstItem + PageSize - 1;
public int TotalPages
{
get
{
var result = (int)Math.Ceiling((double)TotalItems/PageSize);
return result == 0 ? 1 : result;
}
}
public bool HasPreviousPage => PageNumber > 1;
public bool HasNextPage => PageNumber < TotalPages;
public List<T> AsPagination()
{
var numberToSkip = (PageNumber - 1) * PageSize;
var results = Items.Skip(numberToSkip).Take(PageSize).ToList();
return results;
}
}
public class Paginator<T>
{
public List<T> PaginationItems { get; set; }
public int TotalPages { get; set; }
}
我的朋友給了我這個代碼,我無法編譯。在C#中定義一個屬性/方法時,是否有可能以這種方式使用? public int FirstItem =>(PageNumber - 1)* PageSize + 1;這是正確的語法?屬性/方法定義
什麼版本的Visual Studio您使用的?該語法是在VS 2015 – BradleyDotNET
中引入的,您能否給我們提供具體的錯誤?或者它只是說語法錯誤...如果是這樣,在哪一行? –
@BradleyDotNET我使用VS 2013 ... – Kai