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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
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
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.