how can i implement this foreach loop with for loop? because i heard that for loop is much faster than foreach loop.
foreach (RV item in gridview.SelectedItems.ToList())
{
R req= db.Requests.Single(x => x.Id == item.Id);
...
}
You heard incorrectly.
forloops are not much faster thanforeachloops.In fact, for some collections,
foreachloops are much faster thanforloops.ToList()is slower than either of them.If you really want to make your code faster, you should use an O(n) LINQ join instead of the O(n2)
Single()call.