2010-07-18 83 views

Respuesta

13

Puede utilizar LINQ muy fácilmente

bool res = stuff.Any(c => c.ID == 1); 
7
bool isContains = stuff.Any(x => x.ID == 1); 
+0

Devuelve cierto cuando el elemento se encuentra en la lista. –

1
if(stuf.Select(x => x.id).Contains(1)) 
{ 
    //Do Stuff 
} 
+1

DOH, que son 2 itarations ... 1 iteración como 'stuff.Any (s => s.ID == 1);' sería mejor :) –

+1

@ Andreas-niedrmair sólo hay una iteraciones, pero más profunda llamada de función gastos generales –

Cuestiones relacionadas