【发布时间】:2022-01-16 14:36:01
【问题描述】:
我想将字符串转换为 Long。但是我收到了这个错误:
输入的字符串格式不正确
如何在 C# 中将字符串转换为长字符串?
我关注这个答案How could I convert data from string to long in c#
这是我的代码:
if (Convert.ToInt64("140.82") >= minPrice &&
Convert.ToInt64(217.76) <= maxPrice)
{
// do filter
} // on this line the exception is thrown
我犯了什么错误?
【问题讨论】:
-
请注意,该问题的最高投票答案实际上是错误的,并且会给您该错误。
-
既然您在代码中输入值,为什么不将它们输入为十进制而不是字符串(在
217.76的情况下输入其他内容)?
标签: c# asp.net-core