Does the grouping of the sender and the receiver combine outside this method? If so, consider creating a class for them. If not, I would usually use separate local variables, but I suspect it is mostly out of habit.
I suspect we have a couple of local variables here that are conceptually related. Relations may not be strong enough to merit the full type, but it makes sense within the framework of the method. In a sense, using an anonymous type is a very simple way to make this connection obvious. On the other hand, if your method is long enough to really need this additional level of clarity, you might still need to break it.
Please note that using an anonymous type makes some refactoring methods more complicated, because the type is only accessible using the method (without any hacker).
I understand that this is an unsafe answer, but it seems to me that there is some merit in the general idea - it is a bit like using a tuple in a functional language.
source share