79596534

Date: 2025-04-28 13:06:15
Score: 1.5
Natty:
Report link

As of April 28, 2025:

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/null-conditional-assignment

Permits assignment to occur conditionally within a a?.b or a?[b] expression.

using System;

class C
{
    public object obj;
}

void M(C? c)
{
    c?.obj = new object();
}
using System;

class C
{
    public event Action E;
}

void M(C? c)
{
    c?.E += () => { Console.WriteLine("handled event E"); };
}
void M(object[]? arr)
{
    arr?[42] = new object();
}
Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (0.5):
Posted by: D G