AsEnumerable() method in Linq is used to cast or convert given type into it's IEnumerable type. AsEnumerable() basically changes the compile time type of given type that implements IEnumerable
Sample code to use AsEnumerable() in Linq
protected void Page_Load(object sender, EventArgs e)
{
var numArray = new int[5];
numArray[0] = 5;
numArray[1] = 10;
numArray[2] = 7;
numArray[3] = 9;
numArray[4] = 1;
var numbers = numArray.AsEnumerable();
foreach (var number in numbers)
{
Console.WriteLine(number);
}
}
0 Comments :
Post a Comment