我有一个看起来像这样的课程:
class MyHash : IComparable { public byte[] myBytes = new byte[15]; // constructor MyHash(byte[] incomingByteArray) { for (int i = 0; i <= 15; i++) { myBytes[i] = incomingByteArray[i]; } } // other irrelevant stuff here }
现在稍后当我想使用这个类时,我尝试:
MD5 hashMaker = MD5.Create(); byte[] hash = hashMaker.ComputeHash(Encoding.UTF8.GetBytes(thisSubstring)); listOfHashes.Add(new MyHash(hash));
...和Visual Studio(2013)抱怨MyHash"不包含带有1个参数的构造函数".
所以说起来作为ac#novice和可能误用单词来启动,我认为MyHash构造函数正在获得对'hash'的单一引用,它期待的是一个数组......?
我可以破解这个有15个参数的构造函数并实例化它(新的MyHash(hash [0],hash [1]等))但这似乎是错误的事情,我担心我会付钱给它在生活中的程序员.我可以将byte []转换为ArrayList或者其他东西,但是当你在该循环中运行数百万次时会增加相当大的开销.
我也没有看到在构造函数中指定特定数组长度的方法(例如,bytes [15]).
那么将一个字节数组(byte [])发送给构造函数的Correct和True方法是什么?
非常感谢!