C# Error CS0231 – A params parameter must be the last parameter in a formal parameter list

C# Compiler Error

CS0231 – A params parameter must be the last parameter in a formal parameter list

Reason for the Error

You will receive this error if you have multiple parameters in your C# program and the an parameter of type params exists before other parameters.

For example, try to compile the below code snippet.

namespace DeveloperPubNamespace
{
    class Program
    {
        // This will return the C# error code CS0231
        public void ProcessData(params int[] param1, int param2) 
        {
        } 

        public static void Main()
        {
        }
    }
}

This program will result with the C# error code CS0231 because the function ProcessData has the first parameter with params keyword and the second parameter of type int.

Error CS0231 A params parameter must be the last parameter in a formal parameter list DeveloperPublish C:\Users\SenthilBalu\source\repos\ConsoleApp3\ConsoleApp3\Program.cs 6 Active

Solution

To fix the error code CS0231 in C#, you’ll need to ensure that the arguments with the params keyword always appear at the end of the argument list for the method as shown below.

namespace DeveloperPubNamespace
{
    class Program
    {
        // This will return the C# error code CS0231
        public void ProcessData(int param2, params int[] param1) 
        {
        } 

        public static void Main()
        {
        }
    }
}