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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:22:55+00:00 2026-06-12T23:22:55+00:00

One of my methods accepts an out int i as a parameter. I need

  • 0

One of my methods accepts an out int i as a parameter. I need to get the value of this variable and assign it to a local variable.

Consider the following simple console application which demonstrates the issue:.

class Program
    {
        static void Main(string[] args)
        {
            Other o = new Other();
            int i = 5; 
            o.Demo(out i);
            Console.WriteLine(i);
            Console.ReadKey();
        }
    }

    class Other
    {
        public void Demo(out int i)
        {
            // i = 10; Uncomment this to fix it (although this would not be an option)
            int k = i;            
        }
    }

I cannot assign the variable i to k (in the Demo method). Does any one have an explanation (and a work around 🙂 ).

EDIT

The above is just a contrived example of what I’m trying to do: in live, the problem is I’m re-writting code and at this stage, I’m not able to change the “out” as it’s one of the parameters of the constructor which is referenced by many, many other projects! I assume this may mean I’m stuffed

  • 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-12T23:22:57+00:00Added an answer on June 12, 2026 at 11:22 pm

    The point of out is that you must assign a value to the passed in out variable.

    If, as your comments suggests, this is not an option, then you should not be using out for this.

    In order to assign the value, just pass in the value as normal:

    class Other
    {
        public void Demo(int i)
        {
            int k = i;            
        }
    }
    

    Now that you have clarified your use case, I would say that you still need to refactor the out from the constructor. To start, look at overloading the constructor – have an overload that you can use without out and start changing the call sites to the one with out parameters until you have cleared them all out.

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

Sidebar

Related Questions

Suppose we have two overridden versions of a method. One accepts int as argument
I need two methods one to encrypt and one to decrypt an xml file
If I use synchronize(this) in two methods and one calls the other, will I
I have many methods similar to this: void GetColorSky(out float r, out float g,
I want two special methods: one that runs for all URLs one that runs
I have a class for my custom view. One of methods is @Override public
One of my methods sends a message to an object (what do you know
Currently one my DAL methods uses the ExecuteXmlReader command to read and append to
All -- I have these two methods in one of my classes: public static
I've got 2 webclient methods executing one after another. Problem is, the first one

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.