C# Error CS0833 – An anonymous type cannot have multiple properties with the same name

C# Error

CS0833 – An anonymous type cannot have multiple properties with the same name

Reason for the Error & Solution

An anonymous type cannot have multiple properties with the same name.

An anonymous type, just like any type, cannot have two properties that have the same name.

To correct this error

  1. Give each property in the type a unique name.

Example

The following example generates CS0833:

// cs0833.cs  
using System;  
  
public class C  
{  
    public static int Main()  
    {  
        var c = new { p1 = 1, p1 = 2 }; // CS0833  
        return 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...