C# Params Last Updated : 11 Jan, 2025 Comments Improve Suggest changes 19 Likes 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. Create Quiz Comment N niku123 Follow 19 Improve N niku123 Follow 19 Improve Article Tags : Misc C# CSharp-Basics Explore IntroductionC# Tutorial 2 min read Introduction to .NET Framework 6 min read C# .NET Framework (Basic Architecture and Component Stack) 6 min read C# Hello World 2 min read Common Language Runtime (CLR) in C# 4 min read FundamentalsC# Identifiers 2 min read Data Types in C# 6 min read C# Variables 4 min read C# Literals 5 min read Operators in C# 7 min read C# Keywords 5 min read Control StatementsC# Decision Making (if, if-else, if-else-if ladder, nested if, switch, nested switch) 5 min read C# Switch Statement 4 min read Loops in C# 4 min read C# Jump Statements (Break, Continue, Goto, Return and Throw) 4 min read OOP ConceptsClass and Objects in C# 4 min read Constructors in C# 5 min read C# Inheritance 3 min read Encapsulation in C# 2 min read C# Abstraction 4 min read MethodsMethods in C# 4 min read Method Overloading in C# 4 min read Method Parameters in C# 4 min read Method Overriding in C# 7 min read Anonymous Method in C# 2 min read ArraysArrays in C# 6 min read Jagged Arrays in C# 4 min read Array Class in C# 5 min read How to Sort an Array in C# | Array.Sort() Method Set - 1 8 min read How to find the rank of an array in C# 2 min read ArrayListArrayList in C# 6 min read ArrayList Class in C# 4 min read C# | Array vs ArrayList 2 min read StringStrings in C# 6 min read C# Verbatim String Literal - @ 5 min read C# String Class 9 min read C# StringBuilder 2 min read C# String vs StringBuilder 3 min read TupleC# Tuple 7 min read C# Tuple Class 3 min read C# ValueTuple 7 min read C# ValueTuple Struct 4 min read IndexersC# Indexers 5 min read C# Multidimensional Indexers 5 min read C# - Overloading of Indexers 3 min read Like