Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C# VS 2008 windows app HOW DO I RETURN FROM A VOID METHOD?

Posted on 2008-06-17
7
Medium Priority
?
212 Views
Last Modified: 2013-12-16
C# VS 2008 windows app HOW DO I RETURN FROM A VOID METHOD?

In this small code snippet if I have the user click canel how do I return back to whrever in the program they were before this method. It is void so I cannot use return, break doesn't do it? Thoughts? Thanks!

public void btnFullSearch_Click(object sender, EventArgs e)
        {
            MessageBox.Show(" Continue?", "Test", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            RecursiveSearch.RecSearch(txtShare.Text, txtFile.Text);
        }
0
Comment
Question by:Karl66
7 Comments
 
LVL 22

Expert Comment

by:p_davis
ID: 21804033
you can just return;
0
 

Expert Comment

by:mjhoagland
ID: 21804221
Why would you need to return in such a small method anyway?

You show a message box and do a search.  This doesn't look like the place you need to do a return anyway.

A return in your RecSearch() method would be better placed.
0
 

Author Comment

by:Karl66
ID: 21804387
ok a different example - using a CASE I can use BREAK. Assuming I dont want if result == cancel goToThisMethod(); what can I use to just EXIT A METHOD? Thanks.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 18

Expert Comment

by:philipjonathan
ID: 21804393
Change the line

MessageBox.Show(" Continue?", "Test", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

to

if (MessageBox.Show(" Continue?", "Test", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) return;
0
 
LVL 22

Expert Comment

by:p_davis
ID: 21804408
that should work
0
 
LVL 5

Accepted Solution

by:
Hendo1973 earned 1500 total points
ID: 21804410

public void btnFullSearch_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show(" Continue?", "Test", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
               RecursiveSearch.RecSearch(txtShare.Text, txtFile.Text);
        }

Open in new window

0
 
LVL 18

Expert Comment

by:philipjonathan
ID: 21804412
Karl66:
ok a different example - using a CASE I can use BREAK. Assuming I dont want if result == cancel goToThisMethod(); what can I use to just EXIT A METHOD? Thanks.

The answer is "return" :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question