I have a class like this which stores some data to later make a ListView:
public class ListData
{
public string Name{get; set;}
public int ColumnsNumber{get; set;}
//And some other stuff!!
}
Now, I have List<ListData> datas which contains lots of instances of the above class. For making the ListView in detail mode, I need to know the maximum number of required columns. How can I check for this?
At the moment I have:
int max = 0;
foreach(ListData data in datas)
{
if (data.ColumnsNumber > max) max = data.columnsNumber;
}
This seems to work, but is there a better way, or built in method or something in C# for doing this?
you can use LINQ for this:
By this line, you tell LINQ, to map your ListData elements collection into ColumnsNumber collection, and then call Max() which a aggregation method.
In order for this to compile you should add
using System.Linq