如何制作函数选项(我不知道如何调用它)



我正在制作一个人们可以用作登录系统的DLL。
我做的函数目前应该这样编码:

SecureLogin.register.makeUser("Username", "Password", 2);

现在你必须使用 0 = 明文 1 = Idk 但 2 = MD5
但是为了方便起见,我想用这样的东西替换数字 2:

SecureLogin.HashMethod.MD5

我想让它看起来像这样:

SecureLogin.register.makeUser("Username", "Password", SecureLogin.HashMethod.MD5);

如何为此制作方法或函数?
如果我不清楚,请告诉我,我会更详细地描述。

你可以使用枚举:

public enum HashMethod
{
    Plaintext,
    Ldk,
    MD5,
}

然后让你的方法将此枚举作为参数:

public void makeUser(string username, string password, HashMethod method)
{
    if (method == HashMethod.Plaintext)
    {
        ...
    }
    else if (method == HashMethod.Ldk)
    {
        ...
    }
    else if (method == HashMethod.MD5)
    {
        ...
    }
    else
    {
        throw new NotSupportedException("Unknown hash method");
    }
}

然后在调用函数时,您可以传递枚举类型的相应值:

SecureLogin.register.makeUser("Username", "Password", SecureLogin.HashMethod.MD5);

相关内容

最新更新