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

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

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...