c# - oneliner to get biggest something in a list -
i searched on web , can't find if exists.. don't know if question i'll try anyway.
what oneline algorithm retreive biggest in list in c#.
transforming this:
int currentrow = 0; foreach (customfield cf in fieldlist) if (cf.row > currentrow) currentrow = cf.row; in this, row of type int. in advance
use linq (enumerable.max):
int currentrow = fieldlist.max(cf => cf.row); note: source sequence should not empty. if sequence can empty, , want have default value max (i.e. 0 in sample) project sequence , use enumerable.defaultifempty:
int currentrow = fieldlist.select(cf => cf.row).defaultifempty(0).max();
Comments
Post a Comment