system.linq.strings无法访问由于其保护级别

编程入门 行业动态 更新时间:2024-10-25 21:24:24
本文介绍了system.linq.strings无法访问由于其保护级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有,由于琴弦的代码的最后一行中的问题。这是给我的错误 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无法访问由于其保护级别

本文发布于:2023-11-26 20:01:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634986.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:于其   无法访问   级别   system   linq

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!