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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:09:12+00:00 2026-05-11T05:09:12+00:00

Do out parameters in C# have any performance implications I should know about? (Like

  • 0

Do out parameters in C# have any performance implications I should know about? (Like exceptions)

I mean, is it a good idea to have a method with an out parameter in a loop that will run a couple of million times a second?

I know it’s ugly but I am using it the same way as Int32.TryParse is using them – returning a bool to tell if some validation was successful and having an out parameter containing some additional data if it was successful.

  • 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. 2026-05-11T05:09:13+00:00Added an answer on May 11, 2026 at 5:09 am

    I doubt that you’ll find any significant performance penalty to using an out parameter. You’ve got to get information back to the caller somehow or other – out is just a different way of doing it. You may find there’s some penalty if you use the out parameter extensively within the method, as it may well mean an extra level of redirection for each access. However, I wouldn’t expect it to be significant. As normal, write the most readable code and test whether performance is already good enough before trying to optimise further.

    EDIT: The rest of this is an aside, effectively. It’s only really relevant for large value types, which should usually be avoided anyway 🙂

    I disagree with Konrad’s assertion about ‘return values for all types > 32 bit are handled similar or identical to out arguments on the machine level anyway’ though. Here’s a little test app:

    using System; using System.Diagnostics; using System.Runtime.CompilerServices;  struct BigStruct {     public Guid guid1, guid2, guid3, guid4;     public decimal dec1, dec2, dec3, dec4; }  class Test {     const int Iterations = 100000000;      static void Main()     {         decimal total = 0m;         // JIT first         ReturnValue();         BigStruct tmp;         OutParameter(out tmp);          Stopwatch sw = Stopwatch.StartNew();         for (int i=0; i < Iterations; i++)         {             BigStruct bs = ReturnValue();             total += bs.dec1;         }         sw.Stop();         Console.WriteLine('Using return value: {0}',                           sw.ElapsedMilliseconds);          sw = Stopwatch.StartNew();         for (int i=0; i < Iterations; i++)         {             BigStruct bs;             OutParameter(out bs);             total += bs.dec1;         }         Console.WriteLine('Using out parameter: {0}',                           sw.ElapsedMilliseconds);     }      [MethodImpl(MethodImplOptions.NoInlining)]     public static BigStruct ReturnValue()     {         return new BigStruct();     }      [MethodImpl(MethodImplOptions.NoInlining)]     public static void OutParameter(out BigStruct x)     {         x = new BigStruct();     } } 

    Results:

    Using return value: 11316 Using out parameter: 7461 

    Basically by using an out parameter we’re writing the data directly to the final destination, rather than writing it to the small method’s stack frame and then copying it back into the Main method’s stack frame.

    Feel free to criticise the benchmark app though – I may have missed something!

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

Sidebar

Related Questions

Are out parameters a bad thing in .NET? Any good articles/discussions on this topic?
Many times I saw logging of errors like these: System.out.println(Method aMethod with parameters a:+a+
I have a method that has 2 output parameters. The method should take an
I have a method with an out parameter that tries to do a type
Why are 'out' parameters in .NET a bad idea? I was recently asked this,
Any succinct explanations? Also Answered in: Difference between ref and out parameters in .NET
In PL/SQL (or many other languages), I can have IN OUT or OUT parameters,
What is the difference between ref and out parameters in .NET? What are the
The following method does not compile. Visual Studio warns An out parameter may not
Out of the box SSRS reports cannot have data exposed in the page header.

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.