如何解决C#关于方法中UserInput的初学者问题
我是编程新手,正在尝试编写第一个程序。
我想使用用户输入的方法来更改 Main 函数中的变量。 但我收到错误:“无法使用实例引用访问成员‘float.Parse(string)’”
这是我的代码
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 吗?
解决方法
使用
input = float.Parse(usrInput);
代替
input.Parse(usrInput);
参考How to convert a string to a number (C# Programming Guide)。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。