我尝试做的示例代码肯定会比我的英文做得更好:
public bool IsNumericValueInBounds (string value, Type numericType)
{
double d = double.NaN;
bool inBounds = (bool)numericType.GetMethod ("TryParse").Invoke (null, new object[] { value, d });
return inBounds;
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,TryParse方法需要一个out参数,所以这不起作用.任何想法如何解决这个问题?
(ps:这不是鸭子打字的一个很好的例子吗? - 因为我知道每个numericType都有一个"TryParse"或者我错了?)
c# ×1