1. Take
2. Skip
3. TakeWhile
4. SkipWhile
Example SQL Table is UserMsts
Fields : UserMstID, Name, EMail, CreateBy, CreateDate , Address
1. Take Simple Query
var Result = from objUserMst in UserMstsThis Query uses Take to get only the first 8 records.
select objUserMst;
foreach (var n in Result.Take(8))
Console.WriteLine (n.UserMstID + n.Name );
2. Skip
var Result = from objUserMst in UserMstsselect objUserMst;
foreach (var n in Result.Skip(3))This Query uses to SKIP first three record and retrieve rest of the records.
Console.WriteLine ("UserId="+n.UserMstID + "; Name = "+ n.Name );
3. Retrieve records from 10 - 20 for the following results
Records
Query:UserId=
UserId=admin
UserId=AZIZUL
UserId=D00281-000
UserId=D00304-000
UserId=D00611-000
UserId=D01619-000
UserId=D01745-000
UserId=D02669-000
UserId=D02670-0001
UserId=D02673-000
UserId=D02684-000
UserId=D02940-000
UserId=D03002-000
UserId=D03252-000
UserId=D06124-000
UserId=D09533-000
UserId=D09999-001
UserId=D10051-001
UserId=D10059-000
UserId=D11719-000
UserId=D12345-000
UserId=D99999-000
UserId=d99999-999
UserId=DAVID
UserId=Jason
UserId=mradmin
UserId=SOW
UserId=tech_it
UserId=TEST
UserId=test1
UserId=testing
UserId=Testing1
var Result = from objUserMst in UserMsts
Results:
select objUserMst;
foreach (var n in Result.Skip(10).Take(10))
Console.WriteLine ("UserId="+n.UserMstID );
UserId=D02673-0004. TakeWhile
UserId=D02684-000
UserId=D02940-000
UserId=D03002-000
UserId=D03252-000
UserId=D06124-000
UserId=D09533-000
UserId=D09999-001
UserId=D10051-001
UserId=D10059-000
int[] numArray = { 1235, 4456, 1234, 3232, 1900, 80000, 6234, 7123, 2343,0 };The above query TakeWhile to return elements starting from the beginning of the array whether the given(3232) number is hit and retrieved less than 3232 numbers from the array
var FindNumbers = numArray.TakeWhile(n => n < 3232);
foreach (var objFindNumbers in FindNumbers)
{
Console.WriteLine(objFindNumbers);
}
Output:
1235
No comments:
Post a Comment