The Skip() method skips the specified number of element from first element and returns rest of the elements.
Example
-----------------------------------------------
using System;
Example
-----------------------------------------------
using System;
using
System.Collections.Generic;
using
System.Data.SqlClient;
using
System.Data.Sql;
using
System.Data;
using
System.Linq;
using
System.Collections;
using
System.Xml;
using
System.Xml.Linq;
using
System.IO;
namespace
ConsoleApplication1
{
class
Program
{
static
void
Main(string[]
args)
{
int[]
marks = { 10, 20, 30, 40, 50, 60 };
var
newList = marks.Skip(2);
foreach
(var
str in
newList)
Console.WriteLine(str);
Console.ReadKey();
}
}
}
//30
//40
//50
//60
--------------------------------------------
SkipWhile() method skip elements the till the specified condition meet . SkipWhile() returns a new collection that includes all the remaining elements that condition does not meet.
-------------------------------------------------------
-------------------------------------------------------
using
System;
using
System.Collections.Generic;
using
System.Data.SqlClient;
using
System.Data.Sql;
using
System.Data;
using
System.Linq;
using
System.Collections;
using
System.Xml;
using
System.Xml.Linq;
using
System.IO;
namespace
ConsoleApplication1
{
class
Program
{
static
void
Main(string[]
args)
{
int[]
marks = { 10, 20, 30, 40, 50, 60 };
var
newList = marks.SkipWhile(s => s < 40); ;
foreach
(var
str in
newList)
Console.WriteLine(str);
Console.ReadKey();
}
}
}
//40
//50
//60
------------------------------------------------------
The Take() method returns the specified number of elements from starting element to specified number of element.
----------------------------------------------------
using
System;
using
System.Collections.Generic;
using
System.Data.SqlClient;
using
System.Data.Sql;
using
System.Data;
using
System.Linq;
using
System.Collections;
using
System.Xml;
using
System.Xml.Linq;
using
System.IO;
namespace
ConsoleApplication1
{
class
Program
{
static
void
Main(string[]
args)
{
int[]
marks = { 10, 20, 30, 40, 50, 60 };
var
newList = marks.Take(2);
foreach
(var
str in
newList)
Console.WriteLine(str);
Console.ReadKey();
}
}
}
}
//10
//20
---------------------------------- The TakeWhile() extension method returns elements of collection untill specified condition is true.
------------------------------------------
using
System;
using
System.Collections.Generic;
using
System.Data.SqlClient;
using
System.Data.Sql;
using
System.Data;
using
System.Linq;
using
System.Collections;
using
System.Xml;
using
System.Xml.Linq;
using
System.IO;
namespace
ConsoleApplication1
{
class Program
{
static
void
Main(string[]
args)
{
int[]
marks = { 10, 20, 30, 40, 50, 60 };
var
newList = marks.TakeWhile(s => s) <40 font="">40>
foreach
(var
str in
newList)
Console.WriteLine(str);
Console.ReadKey();
}
}
}
//10
//20
//30
-------------------------------------------------
No comments:
Post a Comment