C# Error CS0316 – The parameter name ‘name’ conflicts with an automatically-generated parameter name

C# Compiler Error

CS0316 – The parameter name ‘name’ conflicts with an automatically-generated parameter name.

Reason for the Error

You’ll get this error in your C# code when you have used one of the reserved words in C# as part of the default property or indexer accessor.

For example, lets try to compile the below code snippet.

using System;

namespace DeveloperPublishNamespace
{
    public class Employee
    {
        public int this[int value]   
        {
            get { return value; }
            set { }
        }
    }
    class Program
    {
        
        static void Main(string[] args)
        {
            Employee emp = new Employee();
            
            Console.WriteLine("Hello World!");
        }
    }
}

You’ll receive the error code CS0316 because you are using the reserved keyword “value” for the indexer in the class Employee.

Error CS0316 The parameter name ‘value’ conflicts with an automatically-generated parameter name DeveloperPublish C:\Users\Senthil\source\repos\ConsoleApp4\ConsoleApp4\Program.cs 7 Active

C# Error CS0316 – The parameter name 'name' conflicts with an automatically-generated parameter name

Solution

You can fix this error in your C# program by changing the name of this parameter from the reserved keyword to something that is non-reserved.

using System;

namespace DeveloperPublishNamespace
{
    public class Employee
    {
        public int this[int input]   
        {
            get { return input; }
            set { }
        }
    }
    class Program
    {
        
        static void Main(string[] args)
        {
            Employee emp = new Employee();
            
            Console.WriteLine("Hello World!");
        }
    }
}

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...