我有一个类文件,其中包含一个对输入字符串进行哈希处理的函数。
using System;
using System.Security.Cryptography;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace XHD_Console
{
public class HashingSystem
{
public static string Sha256(string text)
{
string hashString = string.Empty;
//code for hashing here, contains some things i'd rather not release.
return hashString;
}
}
}
我想从表单调用 sha256 函数,智能感知会检测 HashingSystem 类,但不会检测该函数。有理由吗?我读过它需要是静态的,这样做了但无济于事。两个类都位于同一命名空间中,但类 hashingsystem 有自己的文件 hashingsystem.cs
调用该函数:
private void submit_Click(object sender, EventArgs e){
this.EnteredPassword = HashingSystem.sha256(input_Password.Text);
this.DialogResult = DialogResult.OK;
this.Close();
}
你需要打电话static
成员反对class
,不反对instance of a class
。所以你需要使用:
HashingSystem.sha256("texthere");
另外,考虑改变:
class HashingSystem
to:
public class HashingSystem
课程有internal https://stackoverflow.com/questions/824555/why-visual-studio-doesnt-create-a-public-class-by-default默认情况下。我建议您始终明确可见性(即始终指定internal
, public
or private
).
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)