Hi friends,
I have query that is any possible function which can actually tells us that How do we find out the number of parameters passed into function?
Thanks
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Dec 24, 2011, 6:56 AM
using System;
using System.Reflection;
class MyClass
{
public void MyMethod(int i, double d, string s)
{
// do something
}
}
class Test
{
static void Main()
{
Type t = typeof(MyClass);
MethodInfo mi = t.GetMethod("MyMethod");
int count = CountParameters(mi);
Console.WriteLine(count); // 3
Console.ReadKey();
}
static int CountParameters(MethodInfo mi)
{
return mi.GetParameters().Length;
}
}