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 7602139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:20:12+00:00 2026-05-30T23:20:12+00:00

Does C# support a variable number of arguments? If yes, How does C# support

  • 0

Does C# support a variable number of arguments?

If yes, How does C# support variable no of arguments?

What are the examples?

How are variable arguments useful?

EDIT 1: What are the restrictions on it?

EDIT 2: The Question is not about Optional param But Variable Param

  • 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-30T23:20:13+00:00Added an answer on May 30, 2026 at 11:20 pm

    Yes. The classic example wourld be the params object[] args:

    //Allows to pass in any number and types of parameters
    public static void Program(params object[] args)
    

    A typical usecase would be passing parameters in a command line environment to a program, where you pass them in as strings. The program has then to validate and assign them correctly.

    Restrictions:

    • Only one params keyword is permitted per method
    • It has to be the last parameter.

    EDIT: After I read your edits, I made mine. The part below also covers methods to achieve variable numbers of arguments, but I think you really were looking for the params way.


    Also one of the more classic ones, is called method overloading. You’ve probably used them already a lot:

    //both methods have the same name and depending on wether you pass in a parameter
    //or not, the first or the second is used.
    public static void SayHello() {
        Console.WriteLine("Hello");
    }
    public static void SayHello(string message) {
        Console.WriteLine(message);
    }
    

    Last but not least the most exiting one: Optional Arguments

    //this time we specify a default value for the parameter message
    //you now can call both, the method with parameter and the method without.
    public static void SayHello(string message = "Hello") {
        Console.WriteLine(message);
    }
    

    http://msdn.microsoft.com/en-us/library/dd264739.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: tr/// does not support variable interpolation, so I went with s/\Q$_\E//g; instead Or,
Does .NET natively support anything similar to PHP's variable variables ? If not, how
If C does not support passing a variable by reference, why does this work?
I've read that C89 does not support variable-length arrays, but the following experiment seems
Does ODBC support asynchronous calls? If it does, then can you tell me about
Is there a method to pass a variable number of arguments to a function
I've read Java does not support static local variables unlike C/C++. Now if I
Does OpenMP natively support reduction of a variable that represents an array? This would
Does iPhone support XML-RPC, Is their any open source framework which I can use?
Does WPF support using a triggers that respond to routed events but only given

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.