Using your example:
if (new StringBuilder("test") is var sb && sb != null) {
Console.WriteLine(sb);
}
More Related Contents:
- Why aren’t variables declared in “try” in scope in “catch” or “finally”?
- Is there a reason for C#’s reuse of the variable in a foreach?
- Why is Multiple Inheritance not allowed in Java or C#?
- Why are C# 3.0 object initializer constructor parentheses optional?
- C# variable scoping: ‘x’ cannot be declared in this scope because it would give a different meaning to ‘x’
- Variable scope confusion in C#
- How to use Global Variables in C#?
- Why can’t I have abstract static methods in C#?
- What does void mean in C, C++, and C#?
- Why aren’t C# static class extension methods supported?
- Why is The Iteration Variable in a C# foreach statement read-only?
- Variable does not exist in the current context?
- Why are private fields private to the type, not the instance?
- Why do local variables require initialization, but fields do not?
- Why isn’t Array a generic type?
- Why C# won’t allow field initializer with non-static fields?
- Why must we define both == and != in C#?
- Why does C# disallow readonly local variables? [closed]
- Case Statement Block Level Declaration Space in C#
- Private inner classes in C# – why aren’t they used more often?
- Why are const parameters not allowed in C#?
- Performance of “direct” virtual call vs. interface call in C#
- Why is adding null to a string legal?
- C# static member “inheritance” – why does this exist at all?
- I don’t understand why we need the ‘new’ keyword
- Why must C# operator overloads be static?
- variable scope in statement blocks
- TransactionScope With Files In C# [duplicate]
- Why value-types are stored onto Stacks?
- Why use a public method in an internal class?