I building the following anonymous object:
var obj = new {
Country = countryVal,
City = cityVal,
Keyword = key,
Page = page
};
I want to include members in object only if its value is present.
For example if cityVal
is null, I don't want to add City in object initialization
var obj = new {
Country = countryVal,
City = cityVal, //ignore this if cityVal is null
Keyword = key,
Page = page
};
Is this possible in C#?