格式化是指定的,但参数不是IFormattable

Pos*_*Guy 9 c#

string listOfItemPrices = items.ToSemiColonList(item => string.Format("{0:C}", item.Price.ToString()));
Run Code Online (Sandbox Code Playgroud)

我只想把这里的价格格式化为2位小数.好的,所以string.Format没有实现IFormattable?好吧不知道如何解决这个问题,以便我可以在这里格式化小数(价格).

SLa*_*aks 16

通过传递item.Price.ToString()String.Format你传递一个字符串,而不是一个小数.
由于字符串不能与格式字符串一起使用,因此会出现错误.

您需要通过删除来传递Decimal值.String.Format.ToString()