I am populating a Class using LINQ and LinkUrl is a string property of my class.I need to set a value only if a property is not null , other wise no need to assign any values Currently The conditional operator ?: is used
var formattedData = dataset.Select(p => new ListModel
{
Prop1=....,
Prop2=....,
...
LinkUrl = string.IsNullOrWhiteSpace(p.LabelUrl) ? "" : "SET MY PROPERRTY TO A VALUE",
.....
}).ToList();
Can we replace this with C#‘s null-coalescing operator (??) or (?.) or something similar ??
Tne intention is to avoid the repeated use of assigning to "" in so many places
I can write it with operator ?? , but handle cases of NULL only like below .
LinkUrl = p.LabelUrl ?? "SET MY PROPERRTY TO A VALUE"
Can we do something similar for Not null cases