

- 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
Variable Arguments (Varargs) in C#
Use the param keyword to get the variable arguments in C#.
Let us see an example to multiply integers. We have used params keyword to accept any number of int values −
static int Multiply(params int[] b)
The above allows us to find multiplication of numbers with one as well as two int values. The fllowing calls the same function with multiple values −
int mulVal1 = Multiply(5); int mulVal2 = Multiply(5, 10);
Let us see the complete code to understand how variable arguments work in C# −
Example
using System; class Program { static void Main() { int mulVal1 = Multiply(5); int mulVal2 = Multiply(5, 10); Console.WriteLine(mulVal1); Console.WriteLine(mulVal2); } static int Multiply(params int[] b) { int mul =1; foreach (int a in b) { mul = mul*a; } return mul; } }
- Related Questions & Answers
- Using Varargs with standard arguments in Java
- Variable-length arguments in Python
- Demonstrating variable-length arguments in Java
- Variable number of arguments in C++
- What are variable arguments in java?
- Command Line and Variable Arguments in Python?
- Variable length arguments for Macros in C
- Variable number of arguments in Lua Programming
- How to Count Variable Numbers of Arguments in C?
- Overloading Varargs Methods in Java
- Explain about Varargs in java?
- How to use variable-length arguments in a function in Python?
- How to use variable number of arguments to function in JavaScript?
- What are the arguments to Tkinter variable trace method callbacks?
- Convert Kotlin Array to Java varargs
Advertisements