How to assign empty string if the value is null in linq query?

Use the null coalescing operator ??:

FieldValue = field.Value ?? ""

Use the null-coalescing operator

select new { ColumnName = col, FieldValue = field.Value ?? string.Empty };

The ?? operator is called the null-coalescing operator and is used to define a default value for nullable value types or reference types. It returns the left-hand operand if the operand is not null; otherwise it returns the right operand.


FieldValue = field.Value ?? String.Empty

FieldValue = field.Value == null ? "" : field.Value

Tags:

C#

Linq