需要帮助解决一行代码中的错误和其他问题。 [英] Need Help On An Error In One Line Of Code And Something Else.

查看:83
本文介绍了需要帮助解决一行代码中的错误和其他问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我需要帮助修复这行代码,我只是想不通..



 < span class =code-keyword> private   void  btnCheck_Click( object  sender,EventArgs e )
{

if (lbAccounts.SelectedIndex < < span class =code-digit> 0 )
return ;

if (!string.IsNullOrEmpty(txtUser.Text)&&!string.IsNullOrEmpty(txtUser.Text))
return ; // 如果他们有一些数据则停止处理

// 否则得到acccount:密码,
// 将其拆分为acc并传递并将其写入TextBoxes
string value = lbAccounts.Items [lbAccounts.SelectedItem];
// 我收到错误
string [] values = value .Split(' );
if (values.Length!= 2
返回; // 格式错误

var acc = values [ 0 ];
var pass = values [ 1 ];

txtUser.Text = acc;
txtPass.Text = pass;
SendTestMail();
}





如果有人可以帮助我这样做会很棒...而且还指向我的方向如何让它继续阅读并将列表框中的下一个帐户发送到文本框。在此先感谢:)

解决方案

如果你想从列表中获取所选项目,下面的代码就足够了,希望SelectionMode是一个而不是multy。

  string   value  = Convert.ToString(lbAccounts。的SelectedItem); 


So I need help fixing this line of code, and I just can''t figure it out..

private void btnCheck_Click(object sender, EventArgs e)
        {

            if (lbAccounts.SelectedIndex < 0)
                return;

            if (!string.IsNullOrEmpty(txtUser.Text) && !string.IsNullOrEmpty(txtUser.Text))
                return; // stop processing if they have some data

            // otherwise get acccount:password, 
            // split it into acc and pass and write them to TextBoxes
            string value = lbAccounts.Items[lbAccounts.SelectedItem];
            // I am getting the error above
            string[] values = value.Split(':');
            if (values.Length != 2)
                return;  // wrong format        

            var acc = values[0];
            var pass = values[1];

            txtUser.Text = acc;
            txtPass.Text = pass;
            SendTestMail();
        }



If someone can help me do this that would be great... And also point me in the direction of how to make it keep reading and sending the next accounts in line in the listbox to the textbox. Thanks in advance :)

解决方案

If you want to get the selected item from the list the below code is sufficient, hope SelectionMode is one and not multy.

string value = Convert.ToString(lbAccounts.SelectedItem);


这篇关于需要帮助解决一行代码中的错误和其他问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆