How to Resolve Error "CS0100: The parameter name 'name' is a duplicate" in C#
The Compiler Error CS0100 is a naming conflict error. The message reads: "The parameter name 'name' is a duplicate".
In C#, every parameter in a method, constructor, delegate, or lambda expression must have a unique name within that specific signature. The compiler uses these names to identify arguments inside the method body. If two parameters share the same name, the compiler cannot distinguish between them, leading to ambiguity.
This guide explains where these duplicates occur and how to rename them.
Understanding Parameter Uniqueness
When you define a method like void Calculate(int x, int y), the variables x and y become local variables accessible inside the method.
If you write void Calculate(int x, int x), and then type x = 5; inside the method, the compiler asks: "Which 'x' are you referring to? The first one or the second one?" Because C# does not support shadowing parameters within the same signature, this is strictly forbidden.
Scenario 1: Method Definitions
The most common cause is a typo where a developer copy-pastes a parameter argument and forgets to rename it.
Example of error
public class UserProfile
{
// ⛔️ Error CS0100: The parameter name 'id' is a duplicate
// You cannot have two parameters named 'id', even if types are different.
public void UpdateUser(int id, string name, int id)
{
// ...
}
}
Solution: Rename the Parameter
Give the parameters distinct, descriptive names.
public class UserProfile
{
// ✅ Correct: 'id' and 'newId' (or 'sessionId') are distinct.
public void UpdateUser(int userId, string name, int sessionId)
{
// ...
}
}
Scenario 2: Lambda Expressions
This error can also happen in Lambda expressions (anonymous functions), especially when working with nested lambdas or complex LINQ queries where variable names might clash.
Example of error
using System;
public class Program
{
public void Run()
{
Func<int, int, int> add = (x, x) => x + x;
// ⛔️ Error CS0100: The parameter name 'x' is a duplicate
}
}
Solution
Rename one of the parameters.
public class Program
{
public void Run()
{
// ✅ Correct: (x, y) makes the logic clear
Func<int, int, int> add = (x, y) => x + y;
}
}
Conclusion
CS0100 is a simple naming collision.
- Check the Signature: Look at the parameters inside the parentheses
(...). - Find the Duplicate: The error message tells you exactly which name is repeated.
- Rename: Change one of the instances to be unique and descriptive.