Saw something like this in a lazily loaded property getter:
public SomeClass SomeProperty
{
get
{
return _someVar ?? (_someVar = new SomeClass());
}
}
Seems kind of obvious to me what is going on, I just managed to get by using C# for years now without noticing this would work:
int i = 0;
(i = 1).GetType();
I guess my primary question is, does this have some kind of special name I could use to search for more information about it/describe it to others? I guess I’m mostly curious if there are any gotchas associated with it (order of execution, etc, similar to what you’d have to think of when linking multiple null coalescing operators together), or if there are any other standard uses of this like the lazily loaded property getter seen above (even though I don’t think it’s particularly clean compared to the alternatives).
I’m almost embarrassed to post this since it seems like something that would be pretty hard to not have thought about/seen before, haha. Thanks in advance.
This is just a consequence of assignment being an expression in C#. From the C# specification: