问题描述
您好!正如你们中的一些人已经知道了,我正在研究一个比较MD5哈希的软件,我的问题是我如何通过我指导的文件读取我的代码?
public string MD5HashFile( string fn)
{
byte [] hash = MD5.Create()。ComputeHash(File。 ReadAllBytes(FN));
return BitConverter.ToString(hash).Replace( - , );
}
private Stream TestStream()
{
Stream fs = File.OpenRead( @ C:\ PathToDictionary);
return fs;
}
public string GetMD5( string file)
{
using ( var md5 = MD5.Create())
使用( var stream = File.OpenRead (TestStream))
return Encoding.Default.GetString(md5.ComputeHash(stream));
}
这是我目前的代码,正如您可能已经想到的那样,给我一个错误。
更具体地说它告诉我
我的TestStream()方法已经返回一个Stream而File.OpenRead用于创建一个新的Stream,这里不需要,因为TestStream()已经是Stream了。我可以替换使用(var stream = ..... line by var stream = TestStream()
但是...当我这样做时它还在扔我同样的错误,所以我在这里错过了什么?不要轻易对我说,如果有一些我错过的明显的东西,请随时告诉我!
我尝试了什么:
我试过替换使用(var stream = ..... line with var stream = TestStream()
Hello! As some of you already migth know, I am currently working on a software taht compares MD5 Hashes, my question is how do I make my code read through the file I am directing it to?
public string MD5HashFile(string fn) { byte[] hash = MD5.Create().ComputeHash(File.ReadAllBytes(fn)); return BitConverter.ToString(hash).Replace("-", ""); } private Stream TestStream() { Stream fs = File.OpenRead(@"C:\PathToDictionary"); return fs; } public string GetMD5(string file) { using (var md5 = MD5.Create()) using (var stream = File.OpenRead(TestStream)) return Encoding.Default.GetString(md5.ComputeHash(stream)); }
This is my current code and as you probably already figured out, its throwing me an error.
To be more specific its telling me that
My TestStream() method already returns a Stream and File.OpenRead is for creating a new Stream which is not needed here because TestStream() is already a Stream. I can replace the using(var stream=..... line by var stream = TestStream()
But... When I do that its still throwing me the same error so what did I miss here? And dont go easy on me, if there is something obvious that I missed please feel free to tell me!
What I have tried:
Ive tried replace the using(var stream=..... line with var stream = TestStream()
这篇关于如何通过文本文件读取代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!