我有,由于琴弦的代码的最后一行中的问题。这是给我的错误 system.linq.strings无法访问由于其保护级别即使我使用中的 Microsoft.VisualBasic程序命名空间。
专用字节[] CreateKey(字符串strPassword) { //转换strPassword在chrData阵列和存储。 的char [] = chrData strPassword.ToCharArray(); //使用intLength得到strPassword大小。 INT intLength = chrData.GetUpperBound(0); //声明bytDataToHash并使其大小相同chrData。 字节[] = bytDataToHash新的字节[intLength + 1]; //使用对于下一步转换并存储成chrData bytDataToHash。 的for(int i = 0; I< = chrData.GetUpperBound(0);我++){ bytDataToHash [I] = Convert.ToByte(Strings.Asc(chrData [I])); } }解决方案
的行 bytDataToHash [I] = Convert.ToByte(Strings.Asc(chrData [I])); 可能不会做你希望它是什么
您可能希望你的代码做这样的事情:
bytDataToHash = Encoding.Unicode .GetBytes(strPassword);这将让你的密码字节。
但你要使用ASCII? (在升序呼叫提示这一点)。如果你真的不想unicode的,你可以这样做:
bytDataToHash = Encoding.ASCII.GetBytes(strPassword);
但是,一个更好的翻译为坏行是:
Convert.ToByte(chrData [I]); // 不使用!会引起一些数据丢失!
我不知道你为什么想为ASCII值在中间的字符虽然。
I am having a problem with the last line of code because of the strings. It is giving me the error system.linq.strings is inaccessible due to its protection level even though I am using the Microsoft.VisualBasic namespace.
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])); } }解决方案
the line bytDataToHash[i] = Convert.ToByte(Strings.Asc(chrData[i])); probably doesn't do what you want it to.
You probably want your code to do something like this:
bytDataToHash = Encoding.Unicode.GetBytes(strPassword);That will get you the bytes of the password.
But you are trying to use ASCII? (the Asc call hints to that). If you really don't want unicode, you can do this:
bytDataToHash = Encoding.ASCII.GetBytes(strPassword);But a better translation for that bad line is:
Convert.ToByte(chrData[i]); // Do not use! Will cause some data loss!!!I don't know why you'd want to get the ascii value for a character in the interim though.
更多推荐
system.linq.strings无法访问由于其保护级别
发布评论