C# 需要检查输入是否为十进制

C# 需要检查输入是否为十进制,c#,C#,因此,我正在用C#for类编写一个控制台应用程序,我需要弄清楚如何检查输入是否为十进制。它将遵循我到目前为止编写的以下代码: Console.Write("Enter the annual amount of money saved: "); decimal moneySaved = Convert.ToDecimal(Console.ReadLine()); 在它检查输入后,我希望它输出类似“您没有输入数字,请重试”的内容 提前谢谢 你可能想查一下'decimal.tryParse.这很有

因此,我正在用C#for类编写一个控制台应用程序,我需要弄清楚如何检查输入是否为十进制。它将遵循我到目前为止编写的以下代码:

Console.Write("Enter the annual amount of money saved: ");

decimal moneySaved = Convert.ToDecimal(Console.ReadLine());
在它检查输入后,我希望它输出类似“您没有输入数字,请重试”的内容


提前谢谢

你可能想查一下'decimal.tryParse.这很有效,谢谢!如果有帮助的话,标记为答案
 Console.Write("Enter the annual amount of money saved: ");
 string moneySaved = Console.ReadLine();
 decimal number;
 if (Decimal.TryParse(moneySaved, out number))
 {
   Console.Write("You entered a decimal number");
 }
 else
 {
  Console.Write("You didn't enter a number, please try again.");
 }