int[] source= new [] {3,8,4,7,12,9,1}
foreach(var i in source.Where(x =>
{
return (x < 3) || (x > 7);
}
|
static List<T> WhereMethod<T>(IEnumberable<T> source,
Func<T,bool> predicate){
List<T> l = new List<T>();
foreach (T item in source)
if (predicate(item)) {
l.Add(item);
return l;
}
static void Main(string[] args){
int[] source= new [] {3,8,4,7,12,9,1};
var filteredList = WhereMethod(source, i => 5);
// note that the filtered list is not fired until the foreach
foreach (var z in filterList)
Console.WriteLine(z); }
|
static void SomeAsyncMethod(Action complete)
{
Thread.Sleep(1000)
complete();
}
static void Main(string[] args){
{
SomeAsyncMethod(() => {Console.WriteLine("Done");});
}
|