Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将变量从一个文本框移动到公共bool I设置_C# - Fatal编程技术网

C# 如何将变量从一个文本框移动到公共bool I设置

C# 如何将变量从一个文本框移动到公共bool I设置,c#,C#,所以我很新,这是一个愚蠢的问题,但我试图把我在文本框中创建的变量,移动到我创建的布尔值中,我真的不明白。 这里是第一个小剪报,它显示了我想要得到的变量 public FixTheDomain() { InitializeComponent(); } private void FixTheDomain_Load(object sender, EventArgs e) { } public void Pass_Textbo

所以我很新,这是一个愚蠢的问题,但我试图把我在文本框中创建的变量,移动到我创建的布尔值中,我真的不明白。 这里是第一个小剪报,它显示了我想要得到的变量

   public FixTheDomain()

    {
        InitializeComponent();
    }

    private void FixTheDomain_Load(object sender, EventArgs e)
    {

    }

    public void Pass_Textbox(object sender, EventArgs e)
    {
        string Pass; 
        Pass = PassTextbox.Text;\\this is the variable i want

    }
我想把它放进这间屋子里

 public static bool ValidateUser()
    {


       bool validation;
        try
        {
            LdapConnection lcon = new LdapConnection
                    (new LdapDirectoryIdentifier((string)null, false, false));
            NetworkCredential nc = new NetworkCredential(Environment.UserName,
                                 variablegoeshere,Environment.UserDomainName);
            lcon.Credential = nc;
            lcon.AuthType = AuthType.Negotiate;
            // user has authenticated at this point,
            // as the credentials were used to login to the dc.
            lcon.Bind(nc);
            validation = true;
        }
        catch (LdapException)
        {
            validation = false;
        }
        return validation;
    }

修改
ValidateUser
方法,使其采用
string
类型的参数

public static bool ValidateUser(string pass)
{
   bool validation;
   try
   {
       LdapConnection lcon = new LdapConnection
               (new LdapDirectoryIdentifier((string)null, false, false));
       NetworkCredential nc = new NetworkCredential(Environment.UserName,
                            pass,Environment.UserDomainName);
       lcon.Credential = nc;
       lcon.AuthType = AuthType.Negotiate;
       // user has authenticated at this point,
       // as the credentials were used to login to the dc.
       lcon.Bind(nc);
       validation = true;
   }
   catch (LdapException)
   {
       validation = false;
   }
   return validation;
}
然后可以调用它并将参数传递给它:

string Pass; 
Pass = PassTextbox.Text;

bool validation = ValidateUser(Pass);

要在方法之间传递值,最常用的技术是使用

因此,对于您的方法:

public static bool ValidateUser(string pass)
{
    bool validation;
    try
    {
        LdapConnection lcon = new LdapConnection
                (new LdapDirectoryIdentifier((string)null, false, false));
        NetworkCredential nc = new NetworkCredential(Environment.UserName,
                             pass,Environment.UserDomainName);
        lcon.Credential = nc;
        lcon.AuthType = AuthType.Negotiate;
        // user has authenticated at this point,
        // as the credentials were used to login to the dc.
        lcon.Bind(nc);
        validation = true;
    }
    catch (LdapException)
    {
        validation = false;
    }
    return validation;
}
在您的来电者中:

public void Pass_Textbox(object sender, EventArgs e)
{
    string Pass; 
    Pass = PassTextbox.Text;\\this is the variable i want
    ValidateUser(Pass);
}
如何调用
ValidateUser()
?它是静态的,所以理论上你可以使用静态字段,但是。。。什么是事件处理程序
Pass\u Textbox()
?ValidateUser()将在我的表单中的按钮单击上使用,但为了让我有必要将变量传递到此处NetworkCredential nc=新的NetworkCredential(Environment.UserName,variablegoeSher,Environment.UserDomainName);伙计,把名字改成“密码”。快把我逼疯了。