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 8972707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:16:51+00:00 2026-06-15T18:16:51+00:00

I am trying to get to grips with C# having not coded for many

  • 0

I am trying to get to grips with C# having not coded for many years and my previous experience being in ANSI C.

I have read a number of books and searched online but one aspect is evading me and I am hoping someone here can help.

In the past I would declare a function and if there was a possibility of something not happening within the function (i.e. file not found etc.) declare the return to be an integer. I would then return 0 if all was well and a value if not. The value would correspond to where the function failed to execute fully and I could branch accordingly from where I called it.

if(function1())
  {
   // all my error stuff, maybe a switch/case etc.
  }

All the examples I have found in C# seem to avoid this technique and I was hoping to get some understanding here.

Thanks in anticipation.

(I know I am a fossil). 🙂

  • 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-15T18:16:53+00:00Added an answer on June 15, 2026 at 6:16 pm

    If you want to follow that pattern of checking return value instead of managing errors, you better use enumarations than plain numbers.

    For example:

    public enum ResultType
    {
        Error = 0,
        Success,
        Waiting
    }
    
    public ResultType function()
    {
        if (still_waiting)
            return ResultType.Waiting;
    
        if (error_has_occured)
            return ResultType.Error;
    
        return ResultType.Success;
    }
    
    public void Main()
    {
        ResultType result = function();
        switch (result)
        {
            case ResultType.Success:
                MessageBox.Show("all is good");
                break;
            case ResultType.Waiting:
                MessageBox.Show("still waiting...");
                break;
            case ResultType.Error:
                MessageBox.Show("error has occurred");
                break;
        }
    }
    

    Behind the scenes, it’s still using numbers but you put some meaning to each number.

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

Sidebar

Related Questions

I've been trying to get to grips with Core Data and I'm having some
I'm trying to get to grips with Qt's signal and slots mechanism. I have
I'm trying to get to grips with regular expressions: I have a database connection
I am trying to get to grips with programmatically configuring views. I have a
I'm trying to get to grips with Cake's routing, but I'm having no luck
I am trying to get to grips with pdo. I have the below function:
I have been trying to get to grips with Hibernate's inverse attribute, and it
I am trying to get to grips with Jackson JSON parser and have found
I am trying to get to grips with MS Dynamics CRM 2011. I have
I am trying to get to grips with EF4 CTP5. I have two classes

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.