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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:16:07+00:00 2026-06-09T22:16:07+00:00

I can think of the following ways to return multiple values from a method

  • 0

I can think of the following ways to return multiple values from a method (and one which splits into two methods)

private bool IsCarFaulty(Car car, out string fault)
{
  fault = string.Empty;
  return false;
}

private Tuple<bool, string> IsCarFaulty(Car car)
{
  return Tuple.Create(false, string.Empty);
}

private ResultAndMessage IsCarFaulty(Car car)
{
  return new ResultAndMessage(false, string.Empty);
}

private bool IsCarFaulty(Car car)
{
  return false;
}

private string GetCarFault(Car car)
{
  return string.Empty;
}

Basically my question is, are there situations where one is preferable over the other? If I take int.TryParse for an example. It uses an out parameter, but couldn’t splitting it into two methods CanParse and Parse work just as well, if not better.

  • 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-09T22:16:08+00:00Added an answer on June 9, 2026 at 10:16 pm

    Basically my question is, are there situations where one is preferable over the other?

    Sure, but I don’t think there is a general rule that applies to all cases. Just pick the one you feel more comfortable with on a case by case basis.

    I usually avoid using out parameters, because they don’t play well with Linq.

    If I take int.TryParse for an example. It uses an out parameter, but couldn’t splitting it into two methods CanParse and Parse work just as well, if not better.

    Sure, it could work, but that means the string would be parsed twice, which is suboptimal.

    When int.TryParse was introduced, C# didn’t have nullable types (EDIT: actually it did); now you could write a method like that:

    public static int? TryParseInt32(string s)
    {
        int i;
        if (int.TryParse(s, out i))
            return i;
        return null;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One method which I can think of is to reverse the list and then
There are two ways, that I can think of, to obtain similar results from
Given I have two File objects I can think of the following implementation: public
Hoe can I do following thing without using a VIEW from one Query. !--CREATE
The use case I can think of is the following: In a typical application,
I think the following code can be used to create manipulators. #include<iostream> ostream &
I think I'm losing it, can anyone explain why am I experiencing the following:
I can think of lots of ways to do this on my own, but
What I can think of is: Algo: Have a hash table which will store
Given a function: function x(arg) { return 30; } You can call it two

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.