Can I define a shorthand for tuples in C#

273 Views Asked by At

The following function takes an object as a parameter, the object is actually a tuple and is cast as such:

private void MyFunction(object clientWithThreadIDAsObject)
{
    (TcpClient m_sender, int m_nListenerThreadID) clientWithThreadID = ((TcpClient m_sender, int m_nListenerThreadID))clientWithThreadIDAsObject;

Here is the function being called from elsewhere in the code:

(TcpClient m_sender, int m_nListenerThreadID) ClientWithThreadID = (sender, m_nNextListenerThreadID);
                    
MyFunction(ClientWithThreadID);

So the text (TcpClient m_sender, int m_nListenerThreadID) has been written three times.

Is it possible to somehow define a shorthand for this? (Like a macro in c).

Some way to not have to type (TcpClient m_sender, int m_nListenerThreadID) every time it is needed?

0

There are 0 best solutions below