英文:
Incorrect description of the method in the documentation (С#)
问题
当我使用double.TryParse()
方法将字符串转换为浮点数时,该方法返回false
,但文档说一切都应该正常工作。
string message = "12.3";
double number;
bool test = double.TryParse(message, out number);
Console.WriteLine(test);
我尝试在方法中使用不同的浮点数据类型,但没有成功。但如果我在字符串中使用,
作为小数点分隔符,一切都正常工作,尽管方法文档说得不一样。
string message = "12,3";
double number;
bool test = double.TryParse(message, out number);
Console.WriteLine(test);
我在哪里可以获取关于C#方法如何工作的最新信息?
英文:
When I use the double.TryParse() method to convert a string to a floating point number, the method returns false, but the documentation says everything should work
string message = "12.3";
double number;
bool test = double.TryParse(message, out number);
Console.WriteLine(test);
I tried using different floating point data types in the method, but it didn't work
But if I use "," as a decimal separator in the string everything works, although the method documentation says otherwise
string message = "12,3";
double number;
bool test = double.TryParse(message, out number);
Console.WriteLine(test);
Where can I get up-to-date information on how C# methods work?
答案1
得分: -1
string message = "12.3";
double number;
bool test = double.TryParse(message, NumberStyles.Any, CultureInfo.InvariantCulture, out number);
Console.WriteLine(test); // 这应该打印出 true
英文:
string message = "12.3";
double number;
bool test = double.TryParse(message, NumberStyles.Any, CultureInfo.InvariantCulture, out number);
Console.WriteLine(test); // This should print true
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论