我是C#的新手,我正在尝试创建一个安全的登录.我要做的是当输入密码时,密码字符串将被放入一个大小为8的数组中,并且数组的每个字节将被转换为它的ASCII值并存储复制到数组中.
我遇到了诸如"无法将类型'int'隐式转换为'p []'"之类的错误.
  public int hasher(string password, string id)
    {
        int[] p = new int[8];
        int[] a = new int[8];
        p[] = System.Convert.ToInt32(password);
        return 0;
    }
ASCII是byte数据,而不是int;
byte[] bytes = Encoding.ASCII.GetBytes(password);
如果你真的必须有整数:
int[] bytes = Array.ConvertAll(Encoding.ASCII.GetBytes(password), b => (int)b);
请注意,如果任何password非ASCII,那么您将获得未定义的输出.例如,?代替一些字符.