✅ How can i fix this?
i was wondering if someone could help me write my asking for age method error is Local variable 'ageInput' might not be initialized before accessing error in LOC 49
https://paste.mod.gg/kihrmrjohlvd/0
what ive tried and looked at https://stackoverflow.com/questions/57947128/use-of-unassigned-local-variable-in-an-if-statement
and tried changing
but that didnt work either e.o
but that didnt work either e.o
BlazeBin - kihrmrjohlvd
A tool for sharing your source code with the world!
Stack Overflow
Use of unassigned local variable in an if statement
So I'm trying to start coding again(done a year in college before and thinking of going back but need to get back into swing of things. Doing this simple console application and getting this error....
18 Replies
sorry for the double post!
You are not assigning any value to the
ageInput
, neither to age_1
.
If you wanna take any value from user's input, you need to call the Console.ReadLine()
with assignment to the variable.
For example as you did in the Main()
function:
inputText = Console.ReadLine();
Basically the errors occurs cuz you are trying to parse a variable that wasn't initialized with any value yet.
Example solution:
Thank you for the reply i will read into this.
im trying to make a class then a method with the functionality of asking if the user is he/she is and exiting the program if the user underage and continues when the person is older then 18
my brain tells me thats doable
like can i do this outside of the main method?
You can make up another
class
and initialize it to use its properties, methods, etcyeah okay
oh classes go on top!
it's not really important, in general each class should be placed in other file for cleanlines
okay!
some other programming languages needs it, but for C# it's not
this is whati have so far https://paste.mod.gg/aewkbrqlmrvf/0 please ignore the comments i use them to help me learn
BlazeBin - aewkbrqlmrvf
A tool for sharing your source code with the world!
theses are th errors i have

i think i corrected the first one
@Zarez
Non-invocable member 'askingForAge' cannot be used like a method.
is that because i set the return type to void?
You cannot use class as a method:
askingForAge(age);
, that's wrong, you have to initialize the class (call constructor) and then use the class' public methods.
Follow that what I've written here.
Also, the name of classes should start with capital letter.
The void
declaration means that the method doesn't return any data. It doesn't mean that you can't invoke that method.Okay
I’ll look into this tomrrow it’s late af for me rn thanks for the help bud !!