Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8992331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:55:45+00:00 2026-06-15T22:55:45+00:00

My code doesn’t terminate on a true condition if called from another method. For

  • 0

My code doesn’t terminate on a true condition if called from another method. For example,

void RunValidation()
{
    if (NameEntered == string.Empty)
    {
        MessageBox.Show("No name has been entered");
        return;
    }
}

void CreateUser()
{
    RunValidation();

    //Run more code
}

If I call the validation method inside the create user method, the messagebox shows up but the rest of the code gets executed even though “return” was specified.

If the validation code is not inside a method and called directly in the CreateUser method, the rest of the code doesn’t run (which is what I want). I want to be able to call a validation method inside many other methods and if the conditions are true, to stop executing other code in the methods.

What is the correct way of doing this? Do I have to use some sort of try and catch?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:55:46+00:00Added an answer on June 15, 2026 at 10:55 pm

    You are returning from the RunValidation method, not the CreateUser method. If you want to control the flow of the CreateUser method based on the results of RunValidation, do something like this:

    bool Validate()
    {
        if (NameEntered.Equals(string.Empty))
        {
            MessageBox.Show("No name has been entered");
            return false;
        }
        return true;
    }
    
    void CreateUser()
    {
        if (Validate())
        {
            // Run more code
        }
    }
    

    The return statement only affects the current method. Read more about the return statement here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The string called code doesn't seem to read. Why is that and how do
Why below written code doesn't gives error even when string is a reference type.
This code doesn't return data from table: var pom = from k in dataContext.student_gods
The following code doesn't work. $(document).ready(function(){ $(#digitalchange).validate( { rules: { addbalance: { digits:true, min:20,
The following code doesn't work, somehow I can't get the int value from the
This code doesn't work on mysql: update member set member.xy = memba.surba from memba
In the following code doesn't work as public void Foo() { CompanyDataContext db =
this code doesn't work why? private void web_FBCheck_Navigating(object sender, WebBrowserNavigatingEventArgs e) { if (web_FBCheck.Url.ToString()
why the following code doesn't work? internal static string[] GetToolsForRole(string selectedRole) { string[] tempStr;
The following code doesn't work: class String{ public: char* str; int* counter; String(){ str

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.