Number of elements in Tuple <...>

Just wondering if there is an easy way to find out how many elements are contained in the Tuple class.

eg.

 var a = new Tuple<int,int>(1,2);

but how many elements are there? Maybe we don't care if we try to use the as keyword

 var a1 = a as Tuple<int>
 if(a1!=null)

 var a2 = a as Tuple<int,int>
 if(a2!=null)

Just after a little feedback. Many people use Tuple?

+5
source share
1 answer
var a = new Tuple<int, int>(1, 2);
var aType = a.GetType();
var numberOfGenericParameters = aType.GetGenericArguments().Length;
+12
source

All Articles