Reputation: 7830
List<object> lst = new List<object>();
How can I get max value from this list it contains double value.
Upvotes: 0
Views: 1445
Reputation: 1500285
Personally I would use LINQBridge to get you LINQ goodness:
double max = lst.OfType<double>().Max();
It might be overkill to use LINQBridge just for a single "find the maximum element" query, but of course you can then use it everywhere else in your project too... and your code will be more idiomatic when you eventually move off .NET 2 :)
Upvotes: 2
Reputation: 1851
double max = double.MinValue;
foreach (object item in lst)
{
if (item is double)
{
if ((double)item > max)
{
max = (double)item;
}
}
}
Upvotes: 2