Answer the question
In order to leave comments, you need to log in
How to check for null?
Data comes to the model, but there is data that is null;
How can I check for null in a line, and if it's null - insert some line?
For example:
new DataModel()
{
Id = entity.Id,
Name = к примеру, приходит. Я хочу сделать проверку на null, и если тут null вписать string - "Name"
}
Answer the question
In order to leave comments, you need to log in
In general, xs, how did you not think of the simplest thing - through if:
string name;
if(entity.Name == null)
{
name = "Name";
}
else
{
name = entity.Name;
}
DataModel dataModel = new DataModel()
{
Id = entity.Id,
Name = name
};
// ...
new DataModel
{
Id = entity.Id,
Name = entity?.Name ?? "Name"
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question