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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:54:21+00:00 2026-06-07T02:54:21+00:00

I get an error, a red line below the variable intAge in the if-statement

  • 0

I get an error, a red line below the variable intAge in the if-statement in the code. It says the variable is local, but how could it be local when it is declared in the beginning of the code? Does it have to do with the Try/Catch part? The reason why my code looks like it does, is just beacuse I have to use a Try/Catch in the code for this task. Preciate some suggestions to solve this in a similiar and correct way? Thanks!

int intAge;

        try
        {
            intAge = int.Parse(age);
        }
        catch (Exception)
        {
            MessageBox.Show("Enter an age in numbers!","Error!");
        }
        finally
        {

        }
        // Check input
        if (intAge < 1)
        {
            inputOk = false;
            errorMessage = "Please enter 1 or higher!";
        }
  • 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-07T02:54:24+00:00Added an answer on June 7, 2026 at 2:54 am

    just initialize the intAge:

    int intAge = 0;
    

    You are getting error use of unassigned local variable.

    Since you are assigning the value in the try block, the compiler can’t determine if the assignment will take place or not (in case if int.Parse(age) throws an exception), and then in your check if(intAge<1) you are getting the error because you are using a variable not previously assigned.

    Definite assignment – MSDN

    At a given location in the executable code of a function member, a
    variable is said to be definitely assigned if the compiler can prove,
    by static flow analysis, that the variable has been automatically
    initialized or has been the target of at least one assignment.

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

Sidebar

Related Questions

I have some code for a MessageBox, but I get a red line below
Why do I get error in this code?Even if i do not link but
I am using following PHP code for trigger creation but always get error, please
<compilation debug=false targetFramework=4.0> I get this error while that line is red: Parser Error
I don't seem to be able to get the red border line error provider
Why I get error with this query on my live server but not on
I use the following jquery statements but i get error in this function onGetDataSuccess(result)
If I set pre-compile script into binary code to true I get error saying
When I compile the pared-down program below, I get the following error from the
I get error: ORA-06575: Package or function GET_CONC_NAMES is in an invalid state When

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.