So my question is:
Why (and maybe how to avoid it) has the Is-operator in C# a longer lifetime as used in an if?
Example:
Animal a = new Cat();
if (a is Cat c)
{
Console.WriteLine(c); // Works
}
Console.WriteLine(c); // Works too
// Leads to an error because c is allready declared
if (a is Cat c)
{
....
}
What I would expect is, that because I declared the variable c within the if-condition, that it will be scoped to that if-condition, what is not true.
Edit: I understand the bracket argument (a scope starts with the bracked and ends with it). BUT
Why is a for loop that different then?
for (int i = 0; i<3; i++)
{
....
}
Console.WriteLine(i) // error