Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5846335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:33:44+00:00 2026-05-22T12:33:44+00:00

Is it possible to get the number of parameters being passed to a method

  • 0

Is it possible to get the number of parameters being passed to a method in run time, and if so how?

For instance, if if would be possible, I could have a database interaction method as follows,

public void AddSomethingToDatabase(string parameter1, string parameter2)
{
   ...
   foreach(param in parameters)
   {
      sp.AddParameter(GetName(param),param));
   }
   conn.Execute(...);
}

I am attempting to not have to add/change a line in code each time my stored procedure parameters change, instead only changing the method signature with the correct stored procedure parameters. In this case, parameter1 and parameter2 would be the actual names of the parameters in the stored procedure. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:33:45+00:00Added an answer on May 22, 2026 at 12:33 pm

    Can you pass the parameters as a collection? This way it is unlimited and easy to use.
    This is how I do it for my own projects

    public void AddSomethingToDatabase(Dictionary<string, object> parameters)
    {
       foreach(KeyValuePair<string, object> param in parameters)
       {
          string paramname = param.Key;
          object paramvalue= param.Value;
          sp.AddParameter(paramname, paramvalue);
       }
       conn.Execute(...);
    }

    EDIT : I’d like to clarify more how I used this method in my own programs.

    I specify the database procedure parameters in the method itself, and pass the parameters like you do. I do realise there is a better way, like using DTO’s

    public void AddSomethingToDatabase(string param1, int param2)
    {
       Dictionary<string, object> parameters = new Dictionary<string, object>();
       parameters.Add("pID", param1);
       parameters.Add("pName", param2);
    
       ModifyDatabase(parameters, "update_myTable");
    }
    
    public void ModifyDatabase(Dictionary<string, object> parameters, string procedure)
    {
       // Do necessary checks on parameters here
       // Check database availability
       // And many other checks that would be recurring for every database transaction
       // ... that's why I have them all in one place. Executing Queries is the same
       // ... every time. Why would you write the error handling twice? :-)
    
       // Loop parameters and fill procedure parameters
    
       // Execute the lot
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is it possible to configure GET method to read variable number of URI parameters
Is it possible to get at run time the type of a generic class
I was wondering if there was any possible way to get the number (count)
Can we get phone number of device in j2me? Is it possible or not?
So I have a MySQL query that is being created dynamically based on parameters
Possible Duplicate: Get a function's arity Say I have: function a(x) {}; function b(x,y)
Is it possible to get the number of arguments expected of an anonymous function
Is there a way to create a method with unknown number of parameters? And
Possible Duplicate: Why do I always get the same sequence of random numbers with
does anyone know how to (if possible) get the owner of the tag on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.