【发布时间】:2021-09-18 20:27:31
【问题描述】:
我是编程新手,正在尝试做第一个程序。
我想使用用户输入的方法来更改 Main 函数中的变量。 但我得到错误:“成员'float.Parse(字符串)'不能通过实例引用访问”
这是我的代码
public class Program
{
public static void Main()
{ float salary = 0;
float rentalFee;
float powerCosts;
float gez;
bool gezMonth;
float insurence;
bool insurenceMonth;
userOutput("Geben sie einen Wert für ihr Gehalt ein");
salary = UserInput(Console.ReadLine());
Console.WriteLine(salary);
}
private static float UserInput(string usrInput)
{
float input= 0;
input.Parse(usrInput);
return input;
}
我用谷歌搜索了错误,但我真的不明白答案:D 这是因为它的公众吗? 我应该直接在 Main 函数中执行 UserInputs 吗?
【问题讨论】:
-
试试
float input = float.Parse(usrInput);。Parse是一个静态方法,只能从类型而不是实例中静态调用。