Skip to content

Difference in compiler behavior in try.net #175

@BillWagner

Description

@BillWagner

For this code snippet:

object count = "5";

if (count is int number)
    Console.WriteLine(number);
else
    Console.WriteLine($"{number} is not an integer");

The try.net experience compiles and runs, with the message "0 is not an integer".

This is the incorrect behavior. Try the same code locally, and you'll get CS0165 "Use of unassigned local variable 'number'".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions