我对C#很陌生.我正在将VB中的内容转换为C#.遇到此语句的语法问题:
if ((searchResult.Properties["user"].Count > 0))
{
profile.User = System.Text.Encoding.UTF8.GetString(searchResult.Properties["user"][0]);
}
Run Code Online (Sandbox Code Playgroud)
然后我看到以下错误:
参数1:无法从'object'转换为'byte []'
'System.Text.Encoding.GetString(byte [])'的最佳重载方法匹配有一些无效的参数
我试图根据这篇文章修复代码,但仍然没有成功
string User = Encoding.UTF8.GetString("user", 0);
Run Code Online (Sandbox Code Playgroud)
有什么建议?
我有一个用加密哈希加密密码的类.
但是如果我想将null传递给类,我会收到以下错误: Cannot implicitly convert type string to byte[]
这是类代码:
public class MyHash
{
public static string ComputeHash(string plainText,
string hashAlgorithm, byte[] saltBytes)
{
Hash Code
}
}
Run Code Online (Sandbox Code Playgroud)
当我使用该类时,我得到错误:"无法将类型字符串隐式转换为byte []"
//Encrypt Password
byte[] NoHash = null;
byte[] encds = MyHash.ComputeHash(Password, "SHA256", NoHash);
Run Code Online (Sandbox Code Playgroud) 如何在不使用每个元素的情况下将字符串转换"0100"为byte数组?该字符串只能包含字符0到9.{0,1,0,0}Convert.ToByte()