-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Description
Type of issue
Other (describe below)
Description
While writing tests for the Ecma C# spec, I got this error in a context where the method is being called by compiler-generated code rather than by my program, and I thought it might be worth mentioning here.
Consider the following:
MyType q1 = new MyType { 1, 1.2, "abc" };
class MyType : IEnumerable
{
public System.Collections.IEnumerator GetEnumerator()
{
return (IEnumerator)GetEnumerator();
}
}I get this error 3 times, once for each expression in the collection initializer, { 1, 1.2, "abc" }. The reason is that for each expression, the compiler generates a call to Add(type expression), and in my case, type MyType does not have any such method, and one or more (in this case, 3) need to be added. So, while that is covered by your existing explanation, the reason for it is not at all obvious to the new programmer.
Page URL
Content source URL
https://github.com/dotnet/docs/blob/main/docs/csharp/language-reference/compiler-messages/cs1061.md
Document Version Independent Id
df4263c1-477a-3c32-9abe-3fcb850e6c1b
Article author
Metadata
- ID: 60c946d7-649b-44e4-49a9-543565904d18
- Service: dotnet-csharp
- Sub-service: errors-warnings