Click here to Skip to main content
15,903,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

i need a count of parameters in side the method

For example

void m1(int parm1,string parm2)
{
int intcount=// parameter count here (2);
}

C#
void m1(int parm1)
{
  int intcount=// parameter count here (1);
}
Posted
Comments
ArunAmalraj 11-Mar-14 7:10am    
In a Method or Constructor??
Amalraj Ramesh 11-Mar-14 7:16am    
Method
ZurdoDev 11-Mar-14 7:17am    
If you are in the method then you already know the count. Can you explain better what you are really trying to do?
Amalraj Ramesh 11-Mar-14 7:19am    
i dont have any idea..
ZurdoDev 11-Mar-14 7:28am    
What do you mean? If you are writing code inside of a method, to get the count all you have to do is look at it. Why do you think you need to find it programmatically?

1 solution

Unless you use the params keyword, you can't have a variable number of parameters anyway - even if you use the defaulting syntax to omit them when you call it, the actual method will always have the same fixed number of parameters.

If you do use params:
C#
private void MyMethod(params string[] pars)
   {
   ...
   }
Then you can check the number by simply checking the arrays Length property:
C#
private void MyMethod(params string[] pars)
   {
   if (pars.Length > 0)
      {
      ...
      }
   }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900