【发布时间】:2011-09-07 08:31:38
【问题描述】:
我用过很多次扩展方法,都没有遇到过这个问题。有人知道为什么会引发错误吗?
/// <summary>
/// Rounds the specified value.
/// </summary>
/// <param name="value">The value.</param>
/// <param name="decimals">The decimals.</param>
/// <returns></returns>
public static decimal Round (this decimal value, int decimals)
{
return Math.Round(value, decimals);
}
用法:
decimal newAmount = decimal.Parse("3.33333333333434343434");
this.rtbAmount.Text = newAmount.Round(3).ToString();
newAmount.Round(3) 抛出编译器错误:
Error 1 Member 'decimal.Round(decimal)' cannot be accessed with an instance reference; qualify it with a type name instead
【问题讨论】:
标签: c# .net visual-studio-2010 extension-methods rounding