

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are parameter/param arrays in C#?
<p>C# param arrays help if you are not sure of the number of arguments passed as a parameter, while declaring a method.</p><p>The following is the syntax through which you can use the params keyword −</p><pre class="result notranslate">public int function_name(params int[] variable_name) {}</pre><p>Here us an example to learn about param arrays in C# −</p><h2>Example</h2><p><a class="demo" href="http://tpcg.io/WMbLGM" rel="nofollow" target="_blank"> Live Demo</a></p><pre class="prettyprint notranslate" style="">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(); } } }</pre><h2>Output</h2><pre class="result notranslate">The sum is: 1620</pre>
- Related Questions & Answers
- How to use parameter/param arrays in C#?
- How to define param arrays in C#?
- jQuery Misc param() Method
- 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 the improvements in Out Parameter in C# 7.0?
- What are two-dimensional arrays in C#?
- What are variable length (Dynamic) Arrays in Java?
- What are the types of arrays in Java?
- What is final parameter in Java
- What are static or fixed length arrays in C#?
- What are the drawbacks of the arrays in Java?
- What is a final parameter in java?
Advertisements