How do I exit from a function?

前端 未结 7 1289
野的像风
野的像风 2021-02-18 20:18

i know that in vb.net you can just do Exit Sub

but i would like to know how do i exit a click event in a button?

here\'s my code:

pr         


        
7条回答
  •  抹茶落季
    2021-02-18 20:52

    Yo can simply google for "exit sub in c#".

    Also why would you check every text box if it is empty. You can place requiredfieldvalidator for these text boxes if this is an asp.net app and check if(Page.IsValid)

    Or another solution is to get not of these conditions:

    private void button1_Click(object sender, EventArgs e)
    {
        if (!(textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == ""))
        {
            //do events
        }
    }
    

    And better use String.IsNullOrEmpty:

    private void button1_Click(object sender, EventArgs e)
    {
        if (!(String.IsNullOrEmpty(textBox1.Text)
        || String.IsNullOrEmpty(textBox2.Text)
        || String.IsNullOrEmpty(textBox3.Text)))
        {
            //do events
        }
    }
    

提交回复
热议问题