├── .gitattributes ├── .gitignore ├── CSharp8Demo.sln ├── CSharp8Demo ├── 01_IndicesAndRanges.cs ├── 01_RangesImplementation.cs ├── 02_SwitchExpressions.cs ├── 03_PatternMatching.cs ├── 04_StaticLocalFunctions.cs ├── 05_UsingDeclarations.cs ├── 06_NullableReferenceTypes.cs ├── 07_AsyncStreams.cs ├── 08_TargetTypedNew.cs ├── 09_DefaultInterfaceMethods.cs ├── 10_NullCoallescingAssignment.cs ├── 11_ReadonlyStructMembers.cs ├── 12_DisposableRefStruct.cs ├── 13_InterpolatedVerbatimStrings.cs ├── 14_UnmanagedConstructedTypes.cs ├── CSharp8Demo.csproj └── Program.cs ├── LICENSE ├── README.md └── VS2019Demo ├── 01_RegexParser.cs ├── 02_Refactorings_SyncNamespaceAndFolderName.cs ├── 02_Refactorings_TupleToStruct.cs ├── 03_CodeCleanup.cs ├── Folder2 └── Foo.cs ├── FolderName └── Bar.cs ├── Program.cs └── VS2019Demo.csproj /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | *.rptproj.bak 244 | 245 | # SQL Server files 246 | *.mdf 247 | *.ldf 248 | *.ndf 249 | 250 | # Business Intelligence projects 251 | *.rdl.data 252 | *.bim.layout 253 | *.bim_*.settings 254 | *.rptproj.rsuser 255 | 256 | # Microsoft Fakes 257 | FakesAssemblies/ 258 | 259 | # GhostDoc plugin setting file 260 | *.GhostDoc.xml 261 | 262 | # Node.js Tools for Visual Studio 263 | .ntvs_analysis.dat 264 | node_modules/ 265 | 266 | # Visual Studio 6 build log 267 | *.plg 268 | 269 | # Visual Studio 6 workspace options file 270 | *.opt 271 | 272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 273 | *.vbw 274 | 275 | # Visual Studio LightSwitch build output 276 | **/*.HTMLClient/GeneratedArtifacts 277 | **/*.DesktopClient/GeneratedArtifacts 278 | **/*.DesktopClient/ModelManifest.xml 279 | **/*.Server/GeneratedArtifacts 280 | **/*.Server/ModelManifest.xml 281 | _Pvt_Extensions 282 | 283 | # Paket dependency manager 284 | .paket/paket.exe 285 | paket-files/ 286 | 287 | # FAKE - F# Make 288 | .fake/ 289 | 290 | # JetBrains Rider 291 | .idea/ 292 | *.sln.iml 293 | 294 | # CodeRush 295 | .cr/ 296 | 297 | # Python Tools for Visual Studio (PTVS) 298 | __pycache__/ 299 | *.pyc 300 | 301 | # Cake - Uncomment if you are using it 302 | # tools/** 303 | # !tools/packages.config 304 | 305 | # Tabs Studio 306 | *.tss 307 | 308 | # Telerik's JustMock configuration file 309 | *.jmconfig 310 | 311 | # BizTalk build output 312 | *.btp.cs 313 | *.btm.cs 314 | *.odx.cs 315 | *.xsd.cs 316 | 317 | # OpenCover UI analysis results 318 | OpenCover/ 319 | 320 | # Azure Stream Analytics local run output 321 | ASALocalRun/ 322 | 323 | # MSBuild Binary and Structured Log 324 | *.binlog 325 | 326 | # NVidia Nsight GPU debugger configuration file 327 | *.nvuser 328 | 329 | # MFractors (Xamarin productivity tool) working folder 330 | .mfractor/ 331 | -------------------------------------------------------------------------------- /CSharp8Demo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28516.95 5 | MinimumVisualStudioVersion = 15.0.26124.0 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSharp8Demo", "CSharp8Demo\CSharp8Demo.csproj", "{CCD10F7C-A5C4-407F-9031-B04030BA13E9}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VS2019Demo", "VS2019Demo\VS2019Demo.csproj", "{E30B1151-4548-468B-A26A-035E82C78A74}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|x64 = Debug|x64 14 | Debug|x86 = Debug|x86 15 | Release|Any CPU = Release|Any CPU 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {CCD10F7C-A5C4-407F-9031-B04030BA13E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {CCD10F7C-A5C4-407F-9031-B04030BA13E9}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {CCD10F7C-A5C4-407F-9031-B04030BA13E9}.Debug|x64.ActiveCfg = Debug|Any CPU 23 | {CCD10F7C-A5C4-407F-9031-B04030BA13E9}.Debug|x64.Build.0 = Debug|Any CPU 24 | {CCD10F7C-A5C4-407F-9031-B04030BA13E9}.Debug|x86.ActiveCfg = Debug|Any CPU 25 | {CCD10F7C-A5C4-407F-9031-B04030BA13E9}.Debug|x86.Build.0 = Debug|Any CPU 26 | {CCD10F7C-A5C4-407F-9031-B04030BA13E9}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {CCD10F7C-A5C4-407F-9031-B04030BA13E9}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {CCD10F7C-A5C4-407F-9031-B04030BA13E9}.Release|x64.ActiveCfg = Release|Any CPU 29 | {CCD10F7C-A5C4-407F-9031-B04030BA13E9}.Release|x64.Build.0 = Release|Any CPU 30 | {CCD10F7C-A5C4-407F-9031-B04030BA13E9}.Release|x86.ActiveCfg = Release|Any CPU 31 | {CCD10F7C-A5C4-407F-9031-B04030BA13E9}.Release|x86.Build.0 = Release|Any CPU 32 | {E30B1151-4548-468B-A26A-035E82C78A74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {E30B1151-4548-468B-A26A-035E82C78A74}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {E30B1151-4548-468B-A26A-035E82C78A74}.Debug|x64.ActiveCfg = Debug|Any CPU 35 | {E30B1151-4548-468B-A26A-035E82C78A74}.Debug|x64.Build.0 = Debug|Any CPU 36 | {E30B1151-4548-468B-A26A-035E82C78A74}.Debug|x86.ActiveCfg = Debug|Any CPU 37 | {E30B1151-4548-468B-A26A-035E82C78A74}.Debug|x86.Build.0 = Debug|Any CPU 38 | {E30B1151-4548-468B-A26A-035E82C78A74}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {E30B1151-4548-468B-A26A-035E82C78A74}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {E30B1151-4548-468B-A26A-035E82C78A74}.Release|x64.ActiveCfg = Release|Any CPU 41 | {E30B1151-4548-468B-A26A-035E82C78A74}.Release|x64.Build.0 = Release|Any CPU 42 | {E30B1151-4548-468B-A26A-035E82C78A74}.Release|x86.ActiveCfg = Release|Any CPU 43 | {E30B1151-4548-468B-A26A-035E82C78A74}.Release|x86.Build.0 = Release|Any CPU 44 | EndGlobalSection 45 | GlobalSection(SolutionProperties) = preSolution 46 | HideSolutionNode = FALSE 47 | EndGlobalSection 48 | GlobalSection(ExtensibilityGlobals) = postSolution 49 | SolutionGuid = {9B4C0F09-B2C8-46DB-B26E-572A4ECCEBA2} 50 | EndGlobalSection 51 | EndGlobal 52 | -------------------------------------------------------------------------------- /CSharp8Demo/01_IndicesAndRanges.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Haken.CSharp8Demo 8 | { 9 | public class IndicesAndRanges 10 | { 11 | public static void Demo() 12 | { 13 | int[] a = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; 14 | 15 | 16 | Index i1 = 3; // number 3 from beginning (zero-based) 17 | Index i2 = ^4; // number 4 from end ("hat" operator) 18 | 19 | Console.WriteLine($"{a[i1]}, {a[i2]}"); // "3, 6" 20 | 21 | 22 | foreach (var i in a[2..5]) // start index is inclusive, end index is exclusive (non-inclusive)! 23 | { 24 | Console.Write(i); // 234 25 | } 26 | Console.WriteLine(); 27 | 28 | 29 | foreach (var i in a[8..^1]) // start index is inclusive, end index is exclusive (non-inclusive)! 30 | { 31 | Console.Write(i); // 8 32 | } 33 | Console.WriteLine(); 34 | 35 | 36 | foreach (var i in a[3..]) // start/end index only 37 | { 38 | Console.Write(i); // 3456789 39 | } 40 | Console.WriteLine(); 41 | 42 | 43 | foreach (var i in a[..]) // all 44 | { 45 | Console.Write(i); // 0123456789 46 | } 47 | Console.WriteLine(); 48 | 49 | 50 | // under discussion 51 | //foreach (var y in 10..15) 52 | //{ 53 | // Console.Write(y); 54 | //} 55 | 56 | 57 | // under discussion 58 | //var someValue = 3; 59 | //switch (someValue) 60 | //{ 61 | // case 1..5: 62 | // // ... 63 | // break; 64 | //} 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /CSharp8Demo/01_RangesImplementation.cs: -------------------------------------------------------------------------------- 1 | // https://raw.githubusercontent.com/dotnet/csharplang/master/proposals/ranges.cs 2 | namespace System 3 | { 4 | public readonly struct Index 5 | { 6 | private readonly int _value; 7 | 8 | public int Value => _value < 0 ? ~_value : _value; 9 | public bool FromEnd => _value < 0; 10 | 11 | public Index(int value, bool fromEnd) 12 | { 13 | if (value < 0) throw new ArgumentException("Index must not be negative.", nameof(value)); 14 | 15 | _value = fromEnd ? ~value : value; 16 | } 17 | 18 | public static implicit operator Index(int value) 19 | => new Index(value, fromEnd: false); 20 | } 21 | 22 | public readonly struct Range 23 | { 24 | public Index Start { get; } 25 | public Index End { get; } 26 | 27 | private Range(Index start, Index end) 28 | { 29 | this.Start = start; 30 | this.End = end; 31 | } 32 | 33 | public static Range Create(Index start, Index end) => new Range(start, end); 34 | public static Range FromStart(Index start) => new Range(start, new Index(0, fromEnd: true)); 35 | public static Range ToEnd(Index end) => new Range(new Index(0, fromEnd: false), end); 36 | public static Range All() => new Range(new Index(0, fromEnd: false), new Index(0, fromEnd: true)); 37 | } 38 | 39 | static class Extensions 40 | { 41 | public static int get_IndexerExtension(this int[] array, Index index) => 42 | index.FromEnd ? array[array.Length - index.Value] : array[index.Value]; 43 | 44 | public static int get_IndexerExtension(this Span span, Index index) => 45 | index.FromEnd ? span[span.Length - index.Value] : span[index.Value]; 46 | 47 | public static char get_IndexerExtension(this string s, Index index) => 48 | index.FromEnd ? s[s.Length - index.Value] : s[index.Value]; 49 | 50 | public static Span get_IndexerExtension(this int[] array, Range range) => 51 | array.Slice(range); 52 | 53 | public static Span get_IndexerExtension(this Span span, Range range) => 54 | span.Slice(range); 55 | 56 | public static string get_IndexerExtension(this string s, Range range) => 57 | s.Substring(range); 58 | 59 | public static Span Slice(this T[] array, Range range) 60 | => array.AsSpan().Slice(range); 61 | 62 | public static Span Slice(this Span span, Range range) 63 | { 64 | var (start, length) = GetStartAndLength(range, span.Length); 65 | return span.Slice(start, length); 66 | } 67 | 68 | public static string Substring(this string s, Range range) 69 | { 70 | var (start, length) = GetStartAndLength(range, s.Length); 71 | return s.Substring(start, length); 72 | } 73 | 74 | private static (int start, int length) GetStartAndLength(Range range, int entityLength) 75 | { 76 | var start = range.Start.FromEnd ? entityLength - range.Start.Value : range.Start.Value; 77 | var end = range.End.FromEnd ? entityLength - range.End.Value : range.End.Value; 78 | var length = end - start; 79 | 80 | return (start, length); 81 | } 82 | } 83 | } -------------------------------------------------------------------------------- /CSharp8Demo/02_SwitchExpressions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Drawing; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Haken.CSharp8Demo 9 | { 10 | public class SwitchExpressions 11 | { 12 | public static void Demo() 13 | { 14 | var i = 10; 15 | 16 | // basic syntax 17 | var x = i switch // infix 18 | { 19 | 1 => "one", 20 | 2 => "two", 21 | 3 => "three", 22 | _ => "many" // discard = default 23 | }; 24 | Console.WriteLine(x); 25 | 26 | 27 | // supports pattern matching 28 | string Display(object o) => o switch // BTW, local function (C# 7.0) 29 | { 30 | Point p when (p.X == 0) && (p.Y == 0) => "origin", 31 | Point p => $"({p.X}, {p.Y})", 32 | _ => "unknown" 33 | }; 34 | Console.WriteLine(Display(new Point(0, 0))); // origin 35 | 36 | 37 | // same in C# 7.0 - switch statement 38 | string DisplayOld(object o) 39 | { 40 | switch (o) 41 | { 42 | case Point p when (p.X == 0) && (p.Y == 0): 43 | return "origin"; 44 | case Point p: 45 | return $"({p.X}, {p.Y})"; 46 | default: 47 | return "unknown"; 48 | } 49 | } 50 | Console.WriteLine(DisplayOld(new Point(0, 0))); // origin 51 | 52 | // for further improvements see 03_PatternMatching.cs 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /CSharp8Demo/03_PatternMatching.cs: -------------------------------------------------------------------------------- 1 | #nullable disable 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Drawing; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using static Haken.CSharp8Demo.State; 9 | using static Haken.CSharp8Demo.Transition; 10 | 11 | namespace Haken.CSharp8Demo 12 | { 13 | public class PatternMatching 14 | { 15 | public static void Demo() 16 | { 17 | // C# 7.0 18 | string Display0(object o) 19 | { 20 | switch (o) 21 | { 22 | case Point p when (p.X == 0) && (p.Y == 0): 23 | return "origin"; 24 | case Point p: 25 | return $"({p.X}, {p.Y})"; 26 | default: 27 | return "unknown"; 28 | } 29 | } 30 | Console.WriteLine(Display0(new Point(10, 20))); // (10, 20) 31 | 32 | 33 | // Recap: Same as C# 8.0 Switch Expression 34 | string Display1(object o) => o switch 35 | { 36 | Point p when (p.X == 0) && (p.Y == 0) => "origin", 37 | Point p => $"({p.X}, {p.Y})", 38 | _ => "unknown" 39 | }; 40 | Console.WriteLine(Display1(new Point(10, 20))); // (10, 20) 41 | 42 | 43 | // C# 8.0 Property patterns 44 | string Display2(object o) => o switch 45 | { 46 | Point { X: 0, Y: 0 } => "origin", 47 | Point { X: var x, Y: var y } => $"({x}, {y})", 48 | _ => "unknown" 49 | }; 50 | Console.WriteLine(Display2(new Point(10, 20))); // (10, 20) 51 | 52 | 53 | // C# 8.0 Property patterns - not null trick 1 54 | string Display3(object o) => o switch 55 | { 56 | Point { X: 0, Y: 0 } => "origin", 57 | Point { X: var x, Y: var y } => $"({x}, {y})", 58 | { } => o.ToString(), // {} = not null 59 | null => "null" 60 | }; 61 | Console.WriteLine(Display3("blah")); // blah 62 | 63 | 64 | // C# 8.0 Property patterns - not null trick 2 65 | string Display3b(object o) => o switch 66 | { 67 | Point { X: 0, Y: 0 } => "origin", 68 | Point { X: var x, Y: var y } => $"({x}, {y})", 69 | null => "null", 70 | _ => o.ToString(), // deafult => not null 71 | }; 72 | Console.WriteLine(Display3b("blah")); // blah 73 | 74 | 75 | // C# 8.0 Positional patterns - Deconstruction & Tuples 76 | (int x, int y) = new Point(10, 10); 77 | string Display4(object o) => o switch 78 | { 79 | Point(0, 0) => "origin", 80 | Point(var x, var y) => $"({x}, {y})", 81 | _ => "unknown" 82 | }; 83 | Console.WriteLine(Display4(new Point(15, 10))); // (15, 10) 84 | 85 | 86 | // C# 8.0 Tuple patterns 87 | State ChangeState(State current, Transition transition, bool hasKey) => 88 | (current, transition) switch 89 | { 90 | (Opened, Close) => Closed, 91 | (Closed, Open) => Opened, 92 | (Closed, Lock) when hasKey => Locked, 93 | (Locked, Unlock) when hasKey => Closed, 94 | _ => throw new InvalidOperationException($"Invalid transition") 95 | }; 96 | var s = ChangeState(Opened, Close, false); // Closed 97 | 98 | 99 | // C# 8.0 Tuple patterns - more readable? 100 | State ChangeState2(State current, Transition transition, bool hasKey) => 101 | (current, transition, hasKey) switch 102 | { 103 | (Opened, Close, _) => Closed, 104 | (Closed, Open, _) => Opened, 105 | (Closed, Lock, true) => Locked, 106 | (Locked, Unlock, true) => Closed, 107 | _ => throw new InvalidOperationException($"Invalid transition") 108 | }; 109 | var s2 = ChangeState2(Closed, Lock, true); // Locked 110 | 111 | 112 | // C# 8.0 Recursive Patterns - allowing patterns to contain other patterns (1: is Point, 2: X == 0) 113 | object p = new Point(0, 20); 114 | if (p is Point { X: 0, Y: var pY }) 115 | { 116 | Console.WriteLine(pY); 117 | } 118 | } 119 | } 120 | 121 | public static class PointExtensions 122 | { 123 | public static void Deconstruct(this Point p, out int x, out int y) 124 | { 125 | x = p.X; 126 | y = p.Y; 127 | } 128 | } 129 | 130 | public enum State 131 | { 132 | Opened, 133 | Closed, 134 | Locked 135 | } 136 | 137 | public enum Transition 138 | { 139 | Close, 140 | Open, 141 | Lock, 142 | Unlock 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /CSharp8Demo/04_StaticLocalFunctions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Haken.CSharp8Demo 8 | { 9 | public class StaticLocalFunctions 10 | { 11 | public static void Demo() 12 | { 13 | static void DoSomething(object x) 14 | { 15 | Console.WriteLine(x.ToString()); 16 | } 17 | 18 | DoSomething("Calling static local function..."); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /CSharp8Demo/05_UsingDeclarations.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Transactions; 7 | 8 | namespace Haken.CSharp8Demo 9 | { 10 | public class UsingDeclarations 11 | { 12 | public static void Demo() 13 | { 14 | // pre-C# 8.0 15 | using (var transactionScope = new TransactionScope()) 16 | { 17 | // .. 18 | using (var conn = new SqlConnection()) 19 | { 20 | // .. 21 | using (var command = new SqlCommand(conn, "SELECT ...")) 22 | { 23 | // .. 24 | using (var reader = command.ExecuteReader()) 25 | { 26 | // ... 27 | } // reader.Dispose() 28 | } // command.Dispose() 29 | } // conn.Dispose() 30 | transactionScope.Complete(); 31 | } // transactionScope.Dispose(); 32 | 33 | 34 | Console.WriteLine("\nC# 8.0 Using Declarations:"); 35 | for (int i = 0; i < 2; i++) 36 | { 37 | using var transactionScope2 = new TransactionScope(); 38 | using var conn2 = new SqlConnection(); 39 | using var command2 = new SqlCommand(conn2, "SELECT ..."); 40 | using var reader2 = command2.ExecuteReader(); 41 | // ... 42 | transactionScope2.Complete(); 43 | } // disposes all at the end of the current statement block 44 | 45 | 46 | using var conn3 = new SqlConnection(); 47 | } // conn3 disposed at the end of method 48 | } 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | internal class SqlCommand : IDisposable 64 | { 65 | public SqlCommand(SqlConnection conn, string v) 66 | { 67 | } 68 | 69 | public void Dispose() 70 | { 71 | Console.WriteLine("SqlCommand Disposed."); 72 | } 73 | 74 | internal IDisposable ExecuteReader() 75 | { 76 | return new SqlDataReader(); 77 | } 78 | } 79 | 80 | internal class SqlDataReader : IDisposable 81 | { 82 | public void Dispose() 83 | { 84 | Console.WriteLine("SqlDataReader Disposed."); 85 | } 86 | } 87 | 88 | internal class SqlConnection : IDisposable 89 | { 90 | public void Dispose() 91 | { 92 | Console.WriteLine("SqlConnection Disposed."); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /CSharp8Demo/06_NullableReferenceTypes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Haken.CSharp8Demo 8 | { 9 | public class NullableReferenceTypes 10 | { 11 | // https://github.com/dotnet/csharplang/blob/master/proposals/nullable-reference-types-specification.md 12 | // .csproj: enable 13 | 14 | public static void Demo() 15 | { 16 | string s = null; // warning 17 | Console.WriteLine(s); 18 | 19 | 20 | string? s2 = null; // ok 21 | Console.WriteLine(s2.Length); // warning 22 | 23 | 24 | string? s3 = null; // ok 25 | Console.WriteLine(s3!.Length); // dammit! ok (null-forgiving operator; no runtime effect) 26 | 27 | 28 | #nullable disable 29 | string s4 = null; // ok 30 | Console.WriteLine(s4); 31 | #nullable restore 32 | 33 | } 34 | 35 | 36 | public void DoSomething(string? s) 37 | { 38 | if (s != null) 39 | { 40 | Console.WriteLine(s.Length); // ok 41 | } 42 | Console.WriteLine(s.Length); // warning 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /CSharp8Demo/07_AsyncStreams.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Haken.CSharp8Demo 8 | { 9 | public class AsyncStreams 10 | { 11 | public async static Task Demo() 12 | { 13 | await using (var x = new MyAsyncDisposable()) // IAsyncDisposable 14 | { 15 | await foreach (var i in x.GetBigResultsAsync()) // IAsyncEnumerable 16 | { 17 | Console.WriteLine(i); 18 | } 19 | } 20 | } 21 | 22 | public class MyAsyncDisposable : IAsyncDisposable 23 | { 24 | public async IAsyncEnumerable GetBigResultsAsync() 25 | { 26 | await foreach (var result in GetResultsAsync()) 27 | { 28 | if (result > 20) 29 | { 30 | yield return result; 31 | } 32 | } 33 | } 34 | 35 | public async IAsyncEnumerable GetResultsAsync() 36 | { 37 | for (int i = 0; i < 30; i++) 38 | { 39 | await Task.Delay(100); 40 | yield return i; 41 | } 42 | } 43 | 44 | public async ValueTask DisposeAsync() 45 | { 46 | await Task.Delay(200); 47 | Console.WriteLine("Dispose Async..."); 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /CSharp8Demo/08_TargetTypedNew.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Drawing; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Xml; 8 | 9 | namespace Haken.CSharp8Demo 10 | { 11 | public class TargetTypedNew 12 | { 13 | public static void Demo() 14 | { 15 | // Current C# 16 | using (var reader = XmlReader.Create("https://knowledge-base.havit.eu/feed/", new XmlReaderSettings() { IgnoreWhitespace = true })) { } 17 | 18 | // Won't make it into the C# 8.0 - currently "C# 9.0 Candidate" 19 | // using var reader2 = XmlReader.Create("https://knowledge-base.havit.eu/feed/", new() { IgnoreWhitespace = true }); 20 | 21 | // Point[] ps = { new (1, 4), new (3,-2), new (9, 5) }; 22 | // List list = new (10); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /CSharp8Demo/09_DefaultInterfaceMethods.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Haken.CSharp8Demo 8 | { 9 | public class DefaultInterfaceMethods 10 | { 11 | interface ILogger 12 | { 13 | void Log(LogLevel level, string message); 14 | void Log(Exception ex) => Log(LogLevel.Error, "ILogger:" + ex.ToString()); // New overload 15 | } 16 | 17 | public class ConsoleLogger : ILogger 18 | { 19 | public void Log(LogLevel level, string message) { Console.WriteLine(message); } 20 | // ConsoleLogger gets Log(Exception) default implementation 21 | } 22 | 23 | public class AnotherLogger : ILogger 24 | { 25 | public void Log(LogLevel level, string message) { } 26 | public void Log(Exception ex) => Console.WriteLine("AnotherLogger:" + ex.ToString()); 27 | } 28 | 29 | public enum LogLevel 30 | { 31 | Info, 32 | Error 33 | } 34 | 35 | public static void Demo() 36 | { 37 | // won't compile: new ConsoleLogger().Log(new Exception("Test")); 38 | 39 | ((ILogger)new ConsoleLogger()).Log(new Exception("Test1")); // ILogger:System.Exception: Test1 40 | 41 | new AnotherLogger().Log(new Exception("Test3")); // AnotherLogger:System.Exception: Test3 42 | 43 | ((ILogger)new AnotherLogger()).Log(new Exception("Test2")); // AnotherLogger:System.Exception: Test3 44 | 45 | ILogger logger = new AnotherLogger(); 46 | logger.Log(new Exception("Test4")); // AnotherLogger:System.Exception: Test4 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /CSharp8Demo/10_NullCoallescingAssignment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Haken.CSharp8Demo 8 | { 9 | public class NullCoallescingAssignment 10 | { 11 | public static void Demo() 12 | { 13 | object o = 10; 14 | var something = new object(); 15 | 16 | 17 | // pre-C# 8.0 18 | if (o == null) 19 | { 20 | o = something; 21 | } 22 | 23 | 24 | // C# 8.0 - Null Coallescing Assignment Operator ??= 25 | o ??= something; 26 | 27 | Console.WriteLine(o); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /CSharp8Demo/11_ReadonlyStructMembers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Haken.CSharp8Demo 8 | { 9 | // prior to C# 8, only whole struct could be marked as readonly (C# 7.2) or the field-members 10 | public struct MyPoint 11 | { 12 | public double X { get; set; } 13 | public double Y { get; set; } 14 | 15 | public /* readonly */ double Distance => Math.Sqrt(X * X + Y * Y); 16 | 17 | // creates defensive copy of 'this' if the Distance is not marked as read-only 18 | public readonly override string ToString() => 19 | $"({X}, {Y}) is {Distance} from the origin"; 20 | 21 | public /* readonly */ void Translate(int xOffset, int yOffset) 22 | { 23 | X += xOffset; 24 | Y += yOffset; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /CSharp8Demo/12_DisposableRefStruct.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Haken.CSharp8Demo 8 | { 9 | public static class DisposableRefStruct 10 | { 11 | public static void Demo() 12 | { 13 | using (var p = new MyStruct()) 14 | { 15 | 16 | } // p.Dispose() as scope finishes 17 | } 18 | 19 | 20 | public ref struct MyStruct // : IDisposable // ref structs cannot implement interfaces 21 | { 22 | // ref struct = struct that can only live on the stack, such as Span 23 | // ... 24 | 25 | public void Dispose() 26 | { 27 | Console.WriteLine("Disposed..."); 28 | } 29 | } 30 | } 31 | } 32 | // https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8#disposable-ref-structs -------------------------------------------------------------------------------- /CSharp8Demo/13_InterpolatedVerbatimStrings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Haken.CSharp8Demo 9 | { 10 | public class InterpolatedVerbatimStrings 11 | { 12 | public void Demo() 13 | { 14 | string s; 15 | 16 | s = "D:\\Demo"; // string 17 | s = @"D:\Demo"; // @ = verbatim string 18 | s = $"Today {DateTime.Today:g}"; // $ = interpolated string 19 | 20 | s = $@"C# 7 interpolated verbatim string"; // $ must precede @ 21 | 22 | s = @$"C# 8 interpolated verbatim string"; // any @$ order 23 | 24 | 25 | Console.WriteLine(s); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /CSharp8Demo/14_UnmanagedConstructedTypes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Haken.CSharp8Demo 8 | { 9 | // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/unmanaged-types 10 | 11 | public class UnmanagedConstructedTypes 12 | { 13 | public struct Coords 14 | { 15 | public T X; 16 | public T Y; 17 | } 18 | 19 | public static void Demo() 20 | { 21 | // the Coords type is an unmanaged type in C# 8.0 and later 22 | // Like for any unmanaged type, you can create a pointer to a variable of this type 23 | // or allocate a block of memory on the stack for instances of this type: 24 | 25 | Span> coordinates = stackalloc[] 26 | { 27 | new Coords { X = 0, Y = 0 }, 28 | new Coords { X = 0, Y = 3 }, 29 | new Coords { X = 4, Y = 0 } 30 | }; 31 | 32 | DisplaySize>(); 33 | DisplaySize>(); 34 | } 35 | 36 | private unsafe static void DisplaySize() 37 | where T : unmanaged // C# 7.3 - unmanaged constraints 38 | { 39 | Console.WriteLine($"{typeof(T)} is unmanaged and its size is {sizeof(T)} bytes"); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /CSharp8Demo/CSharp8Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | netcoreapp3.0 6 | Haken.CSharp8Demo 7 | Haken.CSharp8Demo 8 | preview 9 | enable 10 | 11 | 12 | 13 | true 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /CSharp8Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.RegularExpressions; 3 | using System.Threading.Tasks; 4 | 5 | namespace Haken.CSharp8Demo 6 | { 7 | class Program 8 | { 9 | async static Task Main(string[] args) 10 | { 11 | Console.WriteLine("\n=== IndicesAndRanges ==="); 12 | IndicesAndRanges.Demo(); 13 | 14 | Console.WriteLine("\n=== SwitchExpressions ==="); 15 | SwitchExpressions.Demo(); 16 | 17 | Console.WriteLine("\n=== PatternMatching ==="); 18 | PatternMatching.Demo(); 19 | 20 | Console.WriteLine("\n=== StaticLocalFunctions ==="); 21 | StaticLocalFunctions.Demo(); 22 | 23 | Console.WriteLine("\n=== UsingDeclarations ==="); 24 | UsingDeclarations.Demo(); 25 | 26 | Console.WriteLine("\n=== AsyncStreams ==="); 27 | await AsyncStreams.Demo(); 28 | 29 | Console.WriteLine("\n=== TargetTypedNew ==="); 30 | TargetTypedNew.Demo(); 31 | 32 | Console.WriteLine("\n=== NullCoallescingAssignment ==="); 33 | NullCoallescingAssignment.Demo(); 34 | 35 | Console.WriteLine("\n=== DefaultInterfaceMethods ==="); 36 | DefaultInterfaceMethods.Demo(); 37 | 38 | Console.WriteLine("\n=== DisposableRefStruct ==="); 39 | DisposableRefStruct.Demo(); 40 | 41 | Console.WriteLine("\n=== UnmanagedConstructedTypes ==="); 42 | UnmanagedConstructedTypes.Demo(); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Robert Haken 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CSharp8Demo 2 | Samples of new C# 8.0 features 3 | -------------------------------------------------------------------------------- /VS2019Demo/01_RegexParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Text.RegularExpressions; 6 | using System.Threading.Tasks; 7 | 8 | namespace VS2019Demo 9 | { 10 | public class RegexParser 11 | { 12 | public static void Demo() 13 | { 14 | var regex = new Regex(@"^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$"); 15 | 16 | 17 | var regex2 = new Regex(@"^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$"); // to test 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /VS2019Demo/02_Refactorings_SyncNamespaceAndFolderName.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace VS2019Demo 8 | { 9 | public class Refactorings_SyncNamespaceAndFolderName 10 | { 11 | public VS2019Demo.Other.Bar Bar { get; set; } 12 | public VS2019Demo.Other.Foo Foo { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /VS2019Demo/02_Refactorings_TupleToStruct.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace VS2019Demo 8 | { 9 | public class Refactorings_TupleToStruct 10 | { 11 | // cursor position :-) 12 | // ___vv______________ 13 | public (int x, int y) GetCoordinates() 14 | { 15 | return (1, 1); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /VS2019Demo/03_CodeCleanup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace VS2019Demo 8 | { 9 | // CLI alternative (new global tool): dotnet.exe format 10 | public class CodeCleanup 11 | { 12 | int x; 13 | object y; 14 | 15 | public CodeCleanup(object y) 16 | { 17 | this.y = y; 18 | } 19 | 20 | public static void Demo() { 21 | 22 | int[] a = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; 23 | 24 | foreach (var i in Enumerable.Range(1, 10)) { 25 | Console.Write(i); 26 | } 27 | Console.WriteLine(); 28 | 29 | 30 | foreach (var i in Enumerable.Range(1, 10)) 31 | Console.Write(i); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /VS2019Demo/Folder2/Foo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace VS2019Demo.Other 8 | { 9 | public class Foo 10 | { 11 | 12 | } 13 | } -------------------------------------------------------------------------------- /VS2019Demo/FolderName/Bar.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace VS2019Demo.Other 8 | { 9 | public class Bar 10 | { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /VS2019Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace VS2019Demo 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Console.WriteLine("Hello World!"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /VS2019Demo/VS2019Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | netcoreapp3.0 6 | preview 7 | 8 | 9 | 10 | --------------------------------------------------------------------------------