Skip to content

[Question] Why the output is CS0165 when using a is Constant pattern. #45582

@InCerryGit

Description

@InCerryGit

Steps to Reproduce:

https://sharplab.io/#v2:D4AQTAjAsAUCDMACciDCiDetE+UkALIgLIAUAlJtrjQG4CGATogC4CmAzi4gLyIB2bAO6IAKhQDc1GjgCWAM1LsuiWRzGIAxgHt+tNo1GduPPvPoAbDm3LSZNEAHYpMezhAQAnKR16DRrgA6ADFtbXIXGgBfWBi4fDAxLFdcBGQIAAZEUO1MAHM2FglrIriooA==

Given the following C# example:

using System;
public class C {
    public void M() {
        var test = new T();
        if(test is T converTest == false)
            return;
        Console.WriteLine(converTest.Foo);
    }
}
public class T{
    public string Foo {get;set;}
}

The following result is returned:

CS0165: Use of unassigned local variable 'converTest '

if converTest is null, the method return . why the output is CS0165 when using a is Constant pattern?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions