Reputation: 21280
How is the best to do following Booking Address is a structure
BookingAddress? retval= null;
here comes my logic and ihave following
BookingAddress address = new BookingAddress(reelinfo.LineID, reelinfo.McID);
retval = address;
Is there more nice way to put the needed value to the retVal ?
Upvotes: 0
Views: 74
Reputation: 6159
This is all you need:
return new BookingAddress(reelinfo.LineID, reelinfo.McID);
You don't really need the retval
variable if you are not doing anything with it between assigining its value and returning it.
Upvotes: 1
Reputation: 108810
Why not simply:
BookingAddress? retval = new BookingAddress(reelinfo.LineID, reelinfo.McID);
A non nullable value type is implicitly convertible to the corresponding nullable value-type.
BookingAddress? retval= null;
if(...)
retval = new BookingAddress(reelinfo.LineID, reelinfo.McID);
Upvotes: 3