I want to get the smallest value in a collection and I am using LINQ to do this. I've read online I can use Min() but I am getting the error message:
At least one object must implement IComparable
This is my code
public virtual void GetBestValue(ModelEnergyCalculator ModelEnergyCalculator)
{
ModelTariffQuote ModelTariffQuote = (from q in ModelEnergyCalculator.ModelTariffQuotes
select q).Min();
}
This is my collection
- - ModelEnergyCalculator {EnergyHelpline.Model.ModelEnergyCalculator} EnergyHelpline.Model.ModelEnergyCalculator
- ModelTariffQuotes Count = 4 System.Collections.Generic.List<EnergyHelpline.Model.ModelTariffQuote>
- [0] {EnergyHelpline.Model.ModelTariffQuote} EnergyHelpline.Model.ModelTariffQuote
ElectricityUsage 0 decimal
FinalElectricityCost 179.97655091937073972602739726 decimal
FinalGasCost 112.48534432460671232876712328 decimal
GasUsage 0 decimal
InitialElectricityCost 30.0117245403146958904109589 decimal
InitialGasCost 18.757327837696684931506849312 decimal
+ QuoteIssuedDate {01/01/0001 00:00:00} System.DateTime
TariffName null string
TotalCalculatedCost 341.23094762198883287671232875 decimal
+ [1] {EnergyHelpline.Model.ModelTariffQuote} EnergyHelpline.Model.ModelTariffQuote
+ [2] {EnergyHelpline.Model.ModelTariffQuote} EnergyHelpline.Model.ModelTariffQuote
+ [3] {EnergyHelpline.Model.ModelTariffQuote} EnergyHelpline.Model.ModelTariffQuote
+ Raw View
+ ModelTariffs Count = 4 System.Collections.Generic.List<EnergyHelpline.Model.ModelTariff>
How do I fix this error or is there a better way for getting the smallest value?