Last active
August 28, 2024 10:40
-
-
Save richardcox13/a92d2d9d83d72f8cc872f847dba7a5a6 to your computer and use it in GitHub Desktop.
C# 13 (.NET 9) required definite assignment for struct typed out parameters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Console.WriteLine("Hello, World!"); | |
| static void GetADateOnly(int dayNo, out DateOnly result) { | |
| if (dayNo == 0) { throw new ArgumentOutOfRangeException(nameof(dayNo)); } | |
| var t = DateOnly.FromDateTime(DateTime.Now); | |
| if (dayNo < 0) { | |
| // Requied as DateOnly has a field... else get CS0177 on the next line | |
| //result = t; | |
| return; | |
| } | |
| result = new DateOnly(t.Year, t.Month, dayNo); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As seen on hovering over the error marker in Visual Studio 17.12.0 Preview 1 with .NET SDK 9.0.100-preview.7.24407.12 imstalled.