方法'接受1个参数
本文关键字:1个 参数 接受 方法 | 更新日期: 2023-09-27 18:14:03
我正在COSMOS中创建一个操作系统,这时我遇到了这个小问题。
else if (HOLOOS.seperate(MyGlobals.input, 5) == "login")
{
if (MyGlobals.input == "login")
{
Console.Write(Commands.login.usage);
}
else
{
var arg = HOLOOS.rseperate(MyGlobals.input, 6, (MyGlobals.input.Length - 1));
arg = HOLOOS.GatherArgs(arg);
login.run(arg);
}
}
这是登录类。我猜是错误的公共静态void运行?
class login
{
public static string CurrentUser;
public static void run(string EnteredUser, string EnteredPassword, string User1CorrectName, string User1CorrectCode, string User2CorrectName = "", string User2CorrectCode = "")
{
string EnteredHashedPassword = BashUtils.Encrypt(EnteredPassword);
//Check if the user name is
if (EnteredUser == User1CorrectName)
{
//If the user name entered is jacob, then check if the password is OK
if (EnteredHashedPassword == BashUtils.Encrypt(User1CorrectCode))
{
//If password is okay than login
Console.Write("You have sucessfully logged in as " + User1CorrectName);
CurrentUser = User1CorrectName;
cd.Path = "D:''" + User1CorrectName + "''";
}
//If the password is not OK then say so
else
{
Console.Write("Not correct password for " + User2CorrectName);
}
}
您在这一行传递了一个参数:
login.run(arg);
到方法run()
方法的签名是:
public static void run(string EnteredUser, string EnteredPassword, string User1CorrectName, string User1CorrectCode, string User2CorrectName = "", string User2CorrectCode = "")
如您所见,前4个参数是强制性的,因此您应该将它们传递给函数。或者修改运行的签名。
最后两个参数有一个默认值,空字符串"。因此,如果你不需要这些值,你就不能传递它们(如果你不将其作为参数传递,它将被分配默认值)。
阅读本文档了解参数和默认值MSDN的完整描述和许多示例。
在这种情况下,我肯定会使用命名参数,但这只是一个意见。阅读文档,如果有什么不明白的就问。