Introduction
I think we are all happy to know that Microsoft has introduced a new Visual Studio known as Visual Studio 2015, in which we will use C# 6.0. There are many new features included in C# 6.0. We know that C# is a very powerful Object Oriented Programming language, so in C# 6.0, there are also some new features that make it more powerful and reliable for users. it has also dropped some features because these features are not so useful for the users, so instead of those features, C# 6.0 has introduced some new features. The dropped features are like a primary constructor, inline declaration, and so on. In C# 6.0, we have some extra features that are very, very useful. Features like Auto-property Enhancements, Using Static, Exception Filters, Name of Expressions, Null-conditional Operators, Index Initializes, Await in catch/finally, params Ienumerable, and many more.
So here I will discuss one of the features that are very useful and very interesting, known as the params Ienumerable, but before learning and discussing the params ienumerable first it is necessary to understand the Params and the ienumerable so let's discuss the params.
Params in C#
Params is a keyword in the C# that plays a very vital role in programming. Using the params keyword, we can pass the value of arguments to the function. Here, we can pass a number of comma-separated arguments. When we compile our code containing the params keyword, all the arguments passed in the method are automatically converted into a temporary array. Then, this array is used for the method for receiving the parameters.
Syntax of Params
static int Sum(params int[] values)
{
// Method body goes here
}
Now, I will make a simple example that makes a method and then explain that example with the params keyword.
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int result = Addition(12, 22, 33);
Console.WriteLine("The sum of num1, num2, and num3 is: " + result);
Console.ReadLine();
}
public static int Addition(int num1, int num2, int num3)
{
return num1 + num2 + num3;
}
}
}
Output

Now, I make this example using the params keyword in C#.
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int result = Addition(1, 2, 3, 4, 5, 6, 7, 8, 9);
Console.WriteLine("The sum of numbers from 1 to 9 is: " + result);
Console.ReadLine();
}
public static int Addition(params int[] listNumbers)
{
int sum = 0;
foreach (int i in listNumbers)
{
sum += i;
}
return sum;
}
}
}
Output

There are the following drawbacks of the params keyword.
- Here, we can use only that value for the function or method that is comma-separated.
- We cannot use the additional keyword in a method if we use the params keyword in it.
- We can use only a single params keyword in the method declaration.
Now, I will discuss the enumerable in C# with you.



Join the conversation! Your thoughts help the community grow.