Compiler Error CS1912
Duplicate initialization of member 'name'.
An object initializer can initialize each member only one time.
- Remove the second initialization of the member in the object initializer.
The following code generates CS1912 because memberA
is initialized two times:
// cs1912.cs
using System.Linq;
public class TestClass
{
public int memberA { get; set; }
public int memberB { get; set; }
}
public class Test
{
static void Main()
{
TestClass tc = new TestClass() { memberA = 5, memberA = 6, memberB = 2}; // CS1912
}
}
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET feedback
.NET is an open source project. Select a link to provide feedback: