C# Params Last Updated : 11 Jan, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Params is an important keyword in C#. It is used as a parameter which can take the variable number of arguments of specific data type. It is a useful feature when the number of arguments is unknown, providing flexibility in method calls. Some key points involved with params in C# are mentioned below: It is useful when programmers don’t know the number of parameters to be used.Only one Params keyword is allowed and no additional Params will be allowed in function declaration after a params keyword.The length of the params will be zero if no arguments are passed.Example: Program to add the elements of array passed on the method C# // Using params keyword using System; class Geeks { // method accepting variable elements // using params public static int Add(params int[] ListNumbers) { int total = 0; // foreach loop foreach(int i in ListNumbers) { total += i; } return total; } // Main Method static void Main(string[] args) { // Elements to accept in Method int y = Add(12, 13, 10, 15, 56); // Displaying result Console.WriteLine(y); } } Output106 RulesSingle params per method: We can only use one params parameter in a method to avoid ambiguity. We need to specify the array type, and all arguments passed must be compatible with that type.Params must be the last parameter: The params keyword should be the last parameter in the method signature to ensure that the method correctly interprets the arguments.Empty array: If no arguments are passed to a params parameter, it will be treated as an empty array.Example 2: Object type Params that allow any type of arguments and any number of arguments. C# // Using Object Type params using System; public class Geeks { // Method with params public string ConcatString(params string[] words) { return string.Join(" ", words); } // Main Method public static void Main() { Geeks sc = new Geeks(); // Calling ConcatString with varying number of // arguments Console.WriteLine(sc.ConcatString("Hello", "Geek")); Console.WriteLine(sc.ConcatString("This", "is", "a", "test")); Console.WriteLine(sc.ConcatString("One")); // without any argument Console.WriteLine(sc.ConcatString()); } } OutputHello Geek This is a test OneExplanation: Here params object[] accepts a variable number of arguments of any type (due to object[]). The resulting method is called with a mix of strings and an integer and shows the flexibility of object[] as the parameter type.Benefits of Using ParamsSimplifies Method Overloading: Without params, we need to create multiple method overloads to handle different numbers of arguments. This increases the complexity and reduces maintainability. Allows the single method to accept any number of arguments.Improved Code Readability: It enhances code readability by eliminating the need to manually create arrays or use multiple overloads. Pass values directly to the method in a comma-separated list, making method calls more easier to read.Flexibility with Argument Count: Allow to pass any number of arguments (including none), making the method more flexible. The method can handle any number of values, making it more versatile and adaptable.Supports Implicit Array: It automatically wraps values in an array. This eliminates the need of explicitly create an array before passing it, improving ease of use. Comment More infoAdvertise with us Next Article C# Params N niku123 Follow Improve Article Tags : Misc C# CSharp-Basics Practice Tags : Misc Similar Reads C# | Method Parameters Methods in C# are generally the block of codes or statements in a program which gives the user the ability to reuse the same code which ultimately saves the excessive use of memory, acts as a time saver and more importantly, it provides better readability of the code. So you can say a method is a co 7 min read Literals in C In C, Literals are the constant values that are assigned to the variables. Literals represent fixed values that cannot be modified. Literals contain memory but they do not have references as variables. Generally, both terms, constants, and literals are used interchangeably. For example, âconst int = 4 min read C# Delegates A delegate is an object which refers to a method or you can say it is a reference type variable that can hold a reference to the methods. It provides a way which tells which method is to be called when an event is triggered. For example, if you click on a Button on a form (Windows Form application), 6 min read Output of C programs | Set 55 1. What will be the output of the following program? C #include <stdio.h> int main() { int a = 03489; printf("%d", a); return (0); } Options: 1. 1865 2. runtime error 3. Syntax error 4. 0 The answer is option(3). Explanation: Any integral value prefix with 0 acts as octal number but 3 min read Parameter Passing Techniques in C In C, passing values to a function means providing data to the function when it is called so that the function can use or manipulate that data. Here:Formal Parameters: Variables used in parameter list in a function declaration/definition as placeholders. Also called only parameters.Actual Parameters 3 min read Like