Studies show that good grammar leads to more promotions and higher salaries. Write with Grammarly

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!");
        }
    }
}