ページ番号関数
5148 ワード
: PageIndex 0 ; PageCount ;
using System;
using System.Collections.Generic;
public class MyClass
{
static int startIndex,endIndex;
static int pageSize=4;
static int pageCount=13;
public static void RunSnippet()
{
for(int i=0;i<21;i++)
g(i);
}
static void g(int pageIndex)
{
GetPageArea(ref startIndex,ref endIndex,pageIndex,pageSize,pageCount);
WL("Page{2}\tArea is : \t{0} \t-- \t{1}",startIndex,endIndex,pageIndex);
}
static void GetPageArea(ref int startIndex, ref int endIndex, int pageIndex, int pageSize, int pageCount)
{
if ( pageSize < 0 || pageCount < 0)
throw new ArgumentException("Maybe args too big!");
if (pageSize == 0 || pageCount == 0)
{
startIndex = 0;
endIndex = 0;
return;
}
if (pageIndex <= pageSize/2)
{
startIndex = 0;
endIndex = pageSize - 1;
return;
}
if (pageIndex > pageCount-pageSize/2-1)
{
startIndex = pageCount - pageSize;
endIndex = pageCount - 1;
return;
}
startIndex = pageIndex - pageSize / 2;
endIndex = pageIndex + pageSize / 2 - (pageSize % 2 == 1 ? 0 : 1);
}
#region Helper methods
public static void Main()
{
try
{
RunSnippet();
}
catch (Exception e)
{
string error = string.Format("---
The following error occurred while executing the snippet:
{0}
---", e.ToString());
Console.WriteLine(error);
}
finally
{
Console.Write("Press any key to continue...");
Console.ReadKey();
}
}
private static void WL(object text, params object[] args)
{
Console.WriteLine(text.ToString(), args);
}
private static void RL()
{
Console.ReadLine();
}
private static void Break()
{
System.Diagnostics.Debugger.Break();
}
#endregion
}
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }