Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
List<string> list = new List<string>();
list.ForEach(delegate(string some_string)
{
Console.WriteLine(some_string);
});
* This source code was highlighted with Source Code Highlighter.
- foreach(var element in collection)
- {
- Console.WriteLine(element);
- }
-
- collection.Each(element => Console.WriteLine(element));
* This source code was highlighted with Source Code Highlighter.using System;
using System.Collections.Generic;
namespace ConsoleApplication1
{
public static class CollectionHelpers
{
public static IEnumerable<T> Each<T>(this IEnumerable<T> list, Action<T> func)
{
if (func == null)
{
return list;
}
if (list == null)
{
return null;
}
foreach (var elem in list)
{
func(elem);
}
return list;
}
}
class Program
{
static void Main(string[] args)
{
var e = new[] {"test", "two", "3"};
e.Each(Console.WriteLine);
}
}
}
* This source code was highlighted with Source Code Highlighter.if (a)
{
}
else
{
}
вместо a?b:cradioButtonList1.Items.Cast<ListItem>().Each(x => x.Selected = true); radioButtonList1.Items.Cast<ListItem>().Select(x => x.Selected = true).ToList();Each(x => {x.Selected = true; x.Text+="_test";}); Select(x => { x.Text += "_test"; return x.Selected = true; }).ToList();Select(x => { x.Text += "_test"; x.Selected = true; return x; }).ToList();public static class Sequence{
public static IEnumerable<S> Select<T,S>(
this IEnumerable<T> source, Func<T,S> selector)
{
foreach (T element in source) yield return selector(element);
}
public static IEnumerable Select<T,S>(
this IEnumerable source, Func<T,S> selector)
{
foreach (T element in source) yield return selector(element);
}
}
* This source code was highlighted with Source Code Highlighter.#define array_foreach(d,a) if(a)for((a)->iterator=0,(d)=array_fetch((a),(a)->iterator);(a)->iterator<(a)->items;(a)->iterator++,(d)=array_fetch((a),(a)->iterator))
ARRAY *a,*c;
unsigned long d;
array_foreach(d,a)
{
array_push(c,d);
}
* This source code was highlighted with Source Code Highlighter.public static IEnumerable<T> For0<T>(this int i, Func<int, T> fnc)
{
for(var j=0;j<i;j++)
yield return fnc(j);
}
* This source code was highlighted with Source Code Highlighter.
Обёртка для foreach