Solved

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

Posted on 2008-06-17
7
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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 500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

617 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