You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using System;publicclassC{publicvoidM(){vartest=new T();if(test is T converTest ==false)return;
Console.WriteLine(converTest.Foo);}}publicclassT{publicstringFoo{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?
The text was updated successfully, but these errors were encountered:
This would require a change to the definite assignment specification. If you want to see this happen, feel free to search for or open an issue in the csharplang repo.
The fact that people keep asking this question is perhaps evidence that something should be done. But the suggestion to do something belongs in csharplang. As it stands the compiler is obeying the specification.
Steps to Reproduce:
https://sharplab.io/#v2:D4AQTAjAsAUCDMACciDCiDetE+UkALIgLIAUAlJtrjQG4CGATogC4CmAzi4gLyIB2bAO6IAKhQDc1GjgCWAM1LsuiWRzGIAxgHt+tNo1GduPPvPoAbDm3LSZNEAHYpMezhAQAnKR16DRrgA6ADFtbXIXGgBfWBi4fDAxLFdcBGQIAAZEUO1MAHM2FglrIriooA==
Given the following C# example:
The following result is returned:
if
converTest
is null, the method return . why the output is CS0165 when using a is Constant pattern?The text was updated successfully, but these errors were encountered: