0

Given the following:

public enum Test
{
    [field: System.ComponentModel.Description("X")]
    X,
    Y,
    Z
}

Visual Studio 2019 says it is a keyword (it isn't listed as a keyword though in the Microsoft docs):

enter image description here

What is 'field:' called and what is it for?

Mike Cheel
  • 12,626
  • 10
  • 72
  • 101
  • https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/attributes/#attribute-targets –  Oct 10 '19 at 17:46
  • Thank you Amy this is exactly what I was looking for. Searching for these words followed by a colon doesn't search very well, even when surrounding with quotes. – Mike Cheel Oct 10 '19 at 17:48
  • Yeah, sometimes knowing what to google is a challenge, and putting my cursor on "field" and hitting F1 didn't help. I didn't know the field target was a thing; I'd only seen this in the context of assembly-level attributes (`[assembly: BlahAttribute`), so on a hunch I googled "c# attribute target". It's curious they aren't called keywords in the docs. –  Oct 10 '19 at 17:54
  • Yea I was really just trying to figure out what they were called. The field target is good for applying attributes to auto property backing fields. – Mike Cheel Oct 10 '19 at 18:32

0 Answers0