C# system.linq.strings由于其保护级别而不可访问

C# system.linq.strings由于其保护级别而不可访问,c#,C#,由于字符串的原因,最后一行代码有问题。它给了我错误system.linq.strings由于其保护级别而无法访问,即使我是 使用Microsoft.VisualBasic命名空间 private byte[] CreateKey(string strPassword) { //Convert strPassword to an array and store in chrData. char[] chrData = strPassword.ToCharArray(); /

由于字符串的原因,最后一行代码有问题。它给了我错误
system.linq.strings由于其保护级别而无法访问,即使我是
使用
Microsoft.VisualBasic
命名空间

private byte[] CreateKey(string strPassword)
{
    //Convert strPassword to an array and store in chrData.
    char[] chrData = strPassword.ToCharArray();
    //Use intLength to get strPassword size.
    int intLength = chrData.GetUpperBound(0);
    //Declare bytDataToHash and make it the same size as chrData.
    byte[] bytDataToHash = new byte[intLength + 1];

    //Use For Next to convert and store chrData into bytDataToHash.
    for (int i = 0; i <= chrData.GetUpperBound(0); i++) {
        bytDataToHash[i] = Convert.ToByte(Strings.Asc(chrData[i]));
    }
}
private byte[]CreateKey(字符串strPassword)
{
//将strPassword转换为数组并存储在chrData中。
char[]chrData=strPassword.ToCharArray();
//使用intLength获取strPassword大小。
int intLength=chrData.GetUpperBound(0);
//声明bytDataToHash并使其与chrData大小相同。
byte[]bytDataToHash=新字节[intLength+1];
//使用For Next将chrData转换并存储为bytDataToHash。

对于(inti=0;i行
bytDataToHash[i]=Convert.ToByte(Strings.Asc(chrData[i]);
可能不符合您的要求

您可能希望代码执行以下操作:

bytDataToHash = Encoding.Unicode.GetBytes(strPassword);
这将获得密码的字节数

但是您正在尝试使用ASCII?(Asc的调用提示)。如果您确实不需要unicode,可以执行以下操作:

bytDataToHash = Encoding.ASCII.GetBytes(strPassword);
但对于这句糟糕的话,更好的翻译是:

Convert.ToByte(chrData[i]); // Do not use! Will cause some data loss!!!
我不知道你为什么要在过渡期间获取字符的ascii值