C# Error CS0225 – The params parameter must be a single dimensional array

C# Compiler Error

CS0225 – The params parameter must be a single dimensional array

Reason for the Error

The params keyword in C# lets you specify a method argument that can take variable number of arguments. You will receive this error when you have not defined the single dimensional array as parameter for params type in the function.

For example, try to compile the below code snippet.

namespace DeveloperPubNamespace
{   
    class Program
    {
        public static void SetUserData(params int input)
        {
        }
        public static void Main()
        {
            SetUserData(1);
        }
    }
}

This program will result with the error code CS0225 because C# compiler has detected that parameter input with params keyword is of type int instead of integer array.

Error CS0225 The params parameter must be a single dimensional array ConsoleApp3 C:\Users\SenthilBalu\source\repos\ConsoleApp3\ConsoleApp3\Program.cs 5 Active

C# Error CS0225 – The params parameter must be a single dimensional array

Solution

To fix the error code CS0225 in C#, you’ll need to change the parameter type to array as shown below.

namespace DeveloperPubNamespace
{   
    class Program
    {
        public static void SetUserData(params int[] input)
        {
        }
        public static void Main()
        {
            SetUserData(1);
        }
    }
}

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...