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

  • Home
  • SEARCH
  • 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 8050713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:08:34+00:00 2026-06-05T07:08:34+00:00

I have a method that returns an object and also has an out parameter.

  • 0

I have a method that returns an object and also has an out parameter. The method calls another method that takes in the same out paramter as another out paramter. This gives a build error on the return statement:

The out parameter ‘param1’ must be assigned to before control leaves
the current method

The code looks like:

public TypeA Method1(TypeA param1, out bool param2)
{
  /... some logic here .../
  SubMethod(out param2);
  /... some logic here .../
  return param1;
}

param2 is manipulated in SubMethod(), not in Method1(). Is there something else I need to do?

  • 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-05T07:08:36+00:00Added an answer on June 5, 2026 at 7:08 am

    In this case, I will assign a ‘default’ value. Regardless of bool, int, myFoo, etc. – set a default value.

    public TypeA Method1(TypeB param1, out bool param2)
    {
      param2 = false;   // default value;
      // or
      param2 = default(bool); // in cases where you are not sure what the default is
    
      /... some logic here .../
      SubMethod(out param2);
      /... some logic here .../
      return param1; // UPDATE: <- this is where you are receiving the exception
    }
    

    But you need to identify why the exception refers to ‘param1’ when param1 is clearly not at fault in this example ( for clarification : assuming TypeB : TypeA and is properly constrained).

    I believe that passing param2 as an out parameter in SubMethod(...) removes the obligation to assign param2. However, you have not assigned anything to param1. Is there more going on here that has not been explained?

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

Sidebar

Related Questions

I have a service method that calls a DAO which then returns an object
I have a controller method that returns a jSON object and in one calling
Suppose I have a Java method that returns a HashMap object. Because a LinkedHashMap
I have my main application delegate which contains a method that returns an object.
I have an object with a method that returns a filehandle, and I want
I have a method with an out parameter that tries to do a type
Suppose I have a method that must return an object (say from a database
I have a method that return a complex JSON object. It's a heavy processing
I have a method that returns a list of type string. I want to
I have a method that returns lot of data, should I use @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) for

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.