-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Description
Type of issue
Outdated article
Description
Hi there!
I was reading Anonymous Types. I tried to grasp three cases in the section Project initializers where the dotnet compiler would not be able to infer member names. The cases are as follows:
The member name isn't inferred in the following cases:
The candidate name is a member name of an anonymous type, such as ToString or GetHashCode.
The candidate name is a duplicate of another property member in the same anonymous type, either explicit or implicit.
The candidate name isn't a valid identifier (for example, it contains spaces or special characters).
I doubt the first case The candidate name is a member name of an anonymous type, such as ToString or GetHashCode. I tried it in dotnetfiddle. However the code was compilable and runnable. Therefore I create this issue to see whether it is possible to delete the first case if I am right.
using System;
public class Program
{
public static void Main()
{
var ToString = "hello world";
var anAnonymous = new { ToString };
Console.WriteLine(anAnonymous.ToString);
}
}What do you think? I'm looking forward to your input.
Page URL
https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/types/anonymous-types
Content source URL
https://github.com/dotnet/docs/blob/main/docs/csharp/fundamentals/types/anonymous-types.md
Document Version Independent Id
dd937177-98f0-a797-d49b-29332aae0614
Platform Id
ecfed45c-63aa-17f6-2cfc-88b1f8bc7adb
Article author
Metadata
- ID: d1b30ebe-b640-449b-3602-9891a55794db
- PlatformId: ecfed45c-63aa-17f6-2cfc-88b1f8bc7adb
- Service: dotnet-csharp
- Sub-service: fundamentals