小编use*_*563的帖子

在 C# 中使用 Double.TryParse 方法转换字符串

现在,我将所有 3 个字符串都转换为 int,但是我在使用 Double.TryParse 方法转换每个字符串时遇到了问题。我想使用该方法而不是 int。

我尝试使用这种类型的代码 if (Double.TryParse(value, out number)),但我不确定这是否正确。

//Ask the user for height
Console.Write("Please enter the first part of your height in feet:");
string _height = Console.ReadLine();
int _heightVal = Int32.Parse(_height);

//Ask the user for inches
Console.Write("Please enter the second part of your height in inches:");
string _inches = Console.ReadLine();
int _inchesVal = Int32.Parse(_inches);

//Ask the user for pounds
Console.Write("Please enter your weight in pounds:");
string _pounds = Console.ReadLine();
int _poundsVal = Int32.Parse(_pounds);
Run Code Online (Sandbox Code Playgroud)

c# string double

2
推荐指数
1
解决办法
4172
查看次数

标签 统计

c# ×1

double ×1

string ×1