![](/img/trans.png)
[英]how to solve Argument 2: cannot convert from 'method group' to 'ResumeAfter<string>' when authenticated in c#.net code
[英]Cannot convert from method group to string when reading file C# .NET
我得到了该软件,该软件可以扫描我选择的文件,然后计算MD5哈希值。
我正在尝试将计算出的MD5哈希值与字典中的哈希值列表进行比较,以查看其是否匹配,以及是否匹配。
如何以编程方式将dictionary.txt添加到我的代码中。
我尝试使用File.OpenRead()
但出现错误提示
参数1:无法从“方法组”转换为“字符串”
我错过了什么?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Security.Cryptography;
namespace MD5_Hash_Compare
{
public partial class lblTitle : Form
{
public lblTitle()
{
InitializeComponent();
}
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));
}
private void lblTitle_Load(object sender, EventArgs e)
{
}
private void scanButton_Click(object sender, EventArgs e)
{
string path = txtFilePath.Text;
//if there is something in the textbox to scan we need to make sure that its doing it.
if (!File.Exists(path))
{
// ... report problem to user.
return;
}
else
{
MessageBox.Show("Scan Complete");
}
hashDisplay.Text = MD5HashFile(path);
}
private void browseButton_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
txtFilePath.Text = (ofd.FileName);
}
}
}
}
在GetMD5
函数中,执行此操作
using (var stream = File.OpenRead(TestStream))
TestStream
是一个函数,因此您需要添加括号来调用它。
using (var stream = File.OpenRead(TestStream()))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.