Skip to content

Instantly share code, notes, and snippets.

@richardcox13
Last active August 28, 2024 10:40
Show Gist options
  • Select an option

  • Save richardcox13/a92d2d9d83d72f8cc872f847dba7a5a6 to your computer and use it in GitHub Desktop.

Select an option

Save richardcox13/a92d2d9d83d72f8cc872f847dba7a5a6 to your computer and use it in GitHub Desktop.
C# 13 (.NET 9) required definite assignment for struct typed out parameters
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);
}
@richardcox13
Copy link
Author

richardcox13 commented Aug 28, 2024

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.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment