
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
What are parameter/param arrays in C#?
C# param arrays help if you are not sure of the number of arguments passed as a parameter, while declaring a method.
The following is the syntax through which you can use the params keyword −
public int function_name(params int[] variable_name) {}
Here us an example to learn about param arrays in C# −
Example
using System; namespace Program { class ParamArray { public int AddElements(params int[] arr) { int sum = 0; foreach (int i in arr) { sum += i; } return sum; } } class Demo { static void Main(string[] args) { ParamArray app = new ParamArray(); int sum = app.AddElements(300, 250, 350, 600, 120); Console.WriteLine("The sum is: {0}", sum); Console.ReadKey(); } } }
Output
The sum is: 1620
- Related Articles
- How to use parameter/param arrays in C#?
- How to define param arrays in C#?
- What are Parameter Tampering Cyber Attacks?
- jQuery Misc param() Method
- What are the improvements in Out Parameter in C# 7.0?
- What are dynamic arrays in C#?
- What are mixed arrays in C#?
- What are jagged arrays in C#?
- What are associative Arrays in JavaScript?
- What are two-dimensional arrays in C#?
- What is final parameter in Java
- What is parameter destructuring in TypeScript?
- What are variable length (Dynamic) Arrays in Java?
- What are the types of arrays in Java?
- What is a final parameter in java?

Advertisements