I’m not sure if I got the right idea of how array.where() works.
I’ve got an array filled with Spectrum.cs objects. each spectrum contains a filename-property.
mySpectrum.filename; //String
Now I have a stringvalue that I want to compare with each object in the array to find out, whether it has the same filename. As I got it it should work like this:
Spectrum bgSpec = new Spectrum(); //Has a filename
Spectrum[] currentSpectra; //Array filled with Spectra
//Somehow this doesn't seem to work. Propably due to the returnvalue for where() which seems //to be IEnumerable.
Spectrum tempSpectrum = currentSpectra.Where<Spectrum>(c => c.filename == bgSpec);
I propably got everything wrong and would be very grateful if somebody could point out what it is or how to do it right.
Thanks in advance,
BC++
It looks like you’re looking for a single value meeting that criterion. So maybe use
Single:Other options:
FirstFirstOrDefaultSingleOrDefaultLastLastOrDefaultThe
OrDefaultversions will returnnullif there’s no matching element. The difference betweenFirst,SingleandLastis in terms of the result for multiple matches:Singlewill throw an exception, whereasFirstorLastwill take the first or last match respectively.Which of these is most appropriate will depend on exactly what you want to do.