Consider that I have a class as follows:
class ProductPrice
{
public string ProductName { get; set; }
public decimal RegularPrice { get; set; }
public decimal SalePrice { get; set; }
}
I have a function like this:
public decimal CalculateDiscount(ProductPrice thePriceInfo)
{
if (thePriceInfo.SalePrice > thePriceInfo.RegularPrice)
throw new ArgumentException("Sale price cannot be greater than regular price.","?????");
return (thePriceInfo.RegularPrice-thePriceInfo.SalePrice) / thePriceInfo.RegularPrice;
}
I'm wondering what I should put in for the ParamName parameter (the ????? above) when I call ArgumentException's constructor.
I'm wondering what the standard conventions are for ParamName when:
1) The parameters causing the exception are nested within a class (i.e. thePriceInfo.SalePrice)
2) The exception is due to an interaction between two different arguments (in this case SalePrice being higher than RegularPrice). Do you separate them by commas or something?
Also, is the ParamName parameter actually used for anything in .NET itself, or popular 3rd party tools, or is it just informational, to be used by other calling code further up the stack?
CalculateDiscount
does not compile. You need to usethePriceInfo
when do the math in thereturn
statement. – Mulish