C
C#2y ago
aj

❔ issues with variable

I have this variable called "remChar" var remChar = Console.ReadLine().ToUpper(); while (remChar == "YES" || remChar == "Y") I want to access the variable later on in the while loop so I can change the information in the variable to look for if it says "No", but when I try to implement it into the code it says " A local or parameter named 'remChar' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter" How would I go by using the variable later on in the code? thank you :)
7 Replies
Thinker
Thinker2y ago
sounds like you tried to redeclare the variable i.e. you wrote var remChar = newValue; instead of remChar = newValue;
MODiX
MODiX2y ago
thinker227#5176
REPL Result: Failure
static void F()
{
var x = 0;

{
var x = 1;
}
}
static void F()
{
var x = 0;

{
var x = 1;
}
}
Exception: CompilationErrorException
- A local or parameter named 'x' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
- A local or parameter named 'x' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
Compile: 497.764ms | Execution: 0.000ms | React with ❌ to remove this embed.
MODiX
MODiX2y ago
thinker227#5176
REPL Result: Success
static void F()
{
var x = 0;

{
x = 1;
}
}
static void F()
{
var x = 0;

{
x = 1;
}
}
Compile: 533.056ms | Execution: 30.773ms | React with ❌ to remove this embed.
aj
ajOP2y ago
is it possible just to use the variable again? because i tried to do remChar(); and it had an error "Method name expected"
Thinker
Thinker2y ago
well remChar isn't a method so you can't call it using () You can use the variable again by just assigning it a new value.
aj
ajOP2y ago
thank you! this fixed my problem
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server