I would like to refactor the following 2 lines of code:
var myDbObject = service.GetObj(id);
name = myDbObject != null ? myDbObject.Name : "No name";
How can I avoid using the auxiliar variable "myDbObject"?
Can I do this with only one line of code?
Is there any way of LINQ or something else to acomplish this?
Solutions that I am not looking:
- using a service that returns the Name and not the full object;
- calling the service more than one time.