Ako koristis C# 3.0 ( Visual Studio 2008 ), mozes da iskoristis IEnumerable ekstenzije nizova i lambda predikat da dodjes do resenja bez svoje For petlje..
Npr, dva nacina preko Aggregate i Where ekstenzija, npr da nadjemo dal sledeci niz ima kao polje2 13 i 15 (mislim da je agregate brzi, zato sto ne generise novi niz, sto Where radi):
Code:
struct MojSlog
{
public int polje1, polje2;
public MojSlog(int p1, int p2) { polje1 = p1; polje2 = p2; }
}
class Program
{
static void Main(string[] args)
{
MojSlog[] niz = { new MojSlog(10, 11),
new MojSlog(14, 18),
new MojSlog(13, 13),
new MojSlog(16, 17)};
// vraca false
bool ima15 = niz.Where(element => element.polje2 == 15).Count() != 0;
// vraca true
bool ima13 = niz.Aggregate(false, (hasEntry, element) => hasEntry |= element.polje2 == 13);
}
}
▪ The word 'politics' is derived from the word 'poly', meaning 'many', and the word 'ticks', meaning 'blood sucking parasites' - Larry Hardiman
▪ If the good guy gets the girl, it's rated PG; if the bad guy gets the girl, it's rated R; and if everybody gets the girl, it's rated X
▪ Illegal aliens have always been a problem in the United States. Ask any Native American