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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:20:20+00:00 2026-06-13T17:20:20+00:00

Why if do this: Object bar; Foo(bar); in C# I get a Use of

  • 0

Why if do this:

Object bar;
Foo(bar);

in C# I get a

Use of unassigned local variable 'bar'

error?

How can I fix it?

  • 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-13T17:20:22+00:00Added an answer on June 13, 2026 at 5:20 pm

    How about assigning a value to the variable before you use it, as the error message states.

    If you are passing the variable to a method you might want to take a look at using out keyword

    The out keyword causes arguments to be passed by reference. This is
    like the ref keyword, except that ref requires that the variable be
    initialized before it is passed. To use an out parameter, both the
    method definition and the calling method must explicitly use the out
    keyword.

    from the link you can see how to use the varaible if you wish to pass to a method and expect the variable to be initialised after that.

    class OutExample
    {
        static void Method(out int i)
        {
            i = 44;
        }
        static void Main()
        {
            int value;
            Method(out value);
            // value is now 44
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object Title : foo Summary : foo bar Body : this
I have the following structure: class foo(object): class bar(object): def __init__(self, parent): self._parent=parent #this
Has anyone way around this bug ? echo json_encode(array('url'=>'/foo/bar')); {url:\/foo\/bar} I use Zend_Json and
Given this object class Contact { public IEnumerable<Person> People { get; } public string
Assuming an XML like this: <my:Root xmlns:my=http://foo/bar> <my:FieldBasic>content</my:FieldBasic> <my:FieldComplex> <html xml:space=preserve xmlns=http://www.w3.org/1999/xhtml> <div><h1>content</h1></div> </html>
How come I can't instantiate an object of type Foo with above constructor? I
I've create WebAPI in .net (my first). Using this api to get object from
I have this object: stdClass Object ( [daily_inventoryID] => 1 [inventory_timestamp] => 2012-06-08 14:35:42
I have this object I'm loading with THREE.objLoader and then create a mesh with
I'm painting this object in C# using GDI and I need to have precise

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.