statusarticleid = x.eventarticlelink != null ? x.eventarticlelink.eventarticle.oid : x.articlesubarticle != null ? x.articlesubarticle.subarticle.oid : 0 simpler in csharp

The original code uses conditional operators to assign a value to the statusarticleid variable based on different conditions. This code can be simplified using the null-coalescing operator ??, as follows:

main.cs
int statusarticleid = 
    x.eventarticlelink?.eventarticle.oid ??
    x.articlesubarticle?.subarticle.oid ?? 0;
113 chars
4 lines

This code checks if eventarticlelink is not null, and if it is not null, it accesses the oid property of the eventarticle. If eventarticlelink is null, it checks if articlesubarticle is not null and if it is not null, it accesses the oid property of the subarticle. If both eventarticlelink and articlesubarticle are null, it assigns the value 0 to statusarticleid.

gistlibby LogSnag