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
I don't understand why I get an error if I use ?. but not if I use != null in the example below.
Version Used:
Visual Studio 16.6.3, .NET Core 3.1 Console Application
Steps to Reproduce:
using System.Collections.Generic;namespaceRoslynTest{classProgram{classSomeClass{publicDictionary<string,string> SomeProperty {get;}=newDictionary<string,string>();}staticSomeClass?MyProperty{get;}staticvoidMain(string[]args){{// Doesn:t workif(MyProperty?.SomeProperty.TryGetValue("key",outvar value)==true){//Error CS0165 Use of unassigned local variable 'value' RoslynTest C:\Users\h165\source\repos\RoslynTest\RoslynTest\Program.cs 21 Active
value.ToString();}// Worksif(MyProperty!=null&& MyProperty.SomeProperty.TryGetValue("key",outvar value2)){//no error
value.ToString();}}}}}
Expected Behavior:
No errors
Actual Behavior:
CS0165
The text was updated successfully, but these errors were encountered:
I first reported this at the roslyn repository , but was told that this is a language thing.
I purpose to refine the definite assignment specification to cover the case described below:
I don't understand why I get an error if I use ?. but not if I use != null in the example below.
Version Used:
Visual Studio 16.6.3, .NET Core 3.1 Console Application
Steps to Reproduce:
Expected Behavior:
No errors
Actual Behavior:
CS0165
The text was updated successfully, but these errors were encountered: