Assume the following code:
DeviceCommunicationDao dao = new DeviceCommunicationDao();
var device = dao.GetDeviceById(123); //returns an object of type "Device"
So I want to assign 2 variables. Is there a way to do this in one line? I mean generally, like via a generic extension method? Something like this:
var device = (new DeviceCommunicationDao() as DeviceCommunicationDao dao).GetDeviceById(123);
I am not looking for lectures on how this is a bad idea and what is confusing or not. I am looking for a one-liner that instantiates 2 variables with a generic approach. Cheers!
If you really want you can create something based on tuples + deconstruction + passing in a
Func
. For example:Or via providing factory:
Or just passing an created instance:
Though I would not say that this is much more readable/convenient.