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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:53:39+00:00 2026-05-15T10:53:39+00:00

As far as I can tell, the only use for out parameters is that

  • 0

As far as I can tell, the only use for out parameters is that a caller can obtain multiple return values from a single method invocation. But we can also obtain multiple result values using ref parameters instead!

So are there other situations where out parameters could prove useful and where we couldn’t use ref parameters instead?

Thank you.

  • 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-05-15T10:53:40+00:00Added an answer on May 15, 2026 at 10:53 am

    Yes – the difference between ref and out is in terms of definite assignment:

    • An out parameter doesn’t have to be definitely assigned by the caller before the method call. It does have to be definitely assigned in the method before it returns normally (i.e. without an exception). The variable is then definitely assigned in the caller after the call.

    • A ref parameter does have to be definitely assigned by the caller before the method call. It doesn’t have to be assigned a different value in the method.

    So suppose we wanted to change int.TryParse(string, out int) to use ref instead. Usually the calling code looks like this:

    int value;
    if (int.TryParse(text, out value))
    {
        // Use value
    }
    else
    {
        // Do something else
    }
    

    Now if we used ref, we’d have to give value a value before the call, e.g.:

    int value = 0;
    if (int.TryParse(text, ref value))
    {
        // Use value
    }
    else
    {
        // Do something else
    }
    

    Obviously it’s not a huge difference – but it gives the wrong impression. We’re assigning a value that we have no intention of ever using, and that’s not a good thing for readability. An out parameter indicates that a value will come out of the method (assuming there’s no exception) and that you don’t need to have a value to start with.

    Once of the suggestions I’ve made for C# 5 (I’ve no idea if it’ll be taken up or not) is that a method with an out parameter should be able to regarded as a method returning a tuple of values. Combined with better support for tuples, that would mean we could do something like this:

    var (ok, value) = int.TryParse(text);
    

    In this case ok and value would be implicitly typed to bool and int respectively. That way it’s clear what’s going into the method (text) and what’s coming out (two pieces of information: ok and value).

    That would simply not be available if int.TryParse used a ref parameter instead – as the compiler can’t know whether it’s going to actually care about the initial value of the ref parameter.

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

Sidebar

Related Questions

That's basically it, as far as I can tell. I can include or require_once
I'm a bit confused here. Microsoft as far as I can tell claims that
As far as I can tell, this is isn't possible, so I'm really just
As far as I can tell, the best way to do this is do
As far as I can tell i'm doing everything by the book, but the
As far as I can tell, there is no API (official or unofficial) to
As far as I can tell, Scala has definitions for the Enumeration Value class
As far as I can tell, this code is fine, and should display some
As far as I can tell I wouldn't think it would make any difference
I have this trigger which works functionally (as far as I can tell by

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.