Why is the “is”-operator in an if a longer scope then the if?
问题 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