0

I have a question, i have a class like the following:

public class RecordedFeatureList
    {
        public string name { get; set; }
        public string type { get; set; }
    }

and when I execute the debugger to see what i'm loading in these fields, the inspector throws me this:

name "the name"

@type "a string"

Any ideas what "@" means before type???

Thanks!

D Stanley
  • 149,601
  • 11
  • 178
  • 240
Hernan Z
  • 3
  • 4
  • `type` is a keyword in c#. When it's used as a name of property or variable the runtime prefix it with @ to distinguish from the keyword. – Chetan Dec 23 '21 at 17:37
  • 1
    Are you sure you copied that correctly? Is the name of the property really `type` and not `Type`? – PMF Dec 23 '21 at 17:37
  • "type" is *not* a [keyword in C#](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/). *`typeof`* is, but not "type". – madreflection Dec 23 '21 at 17:37
  • 1
    It means you've loaded a [footgun](https://en.wiktionary.org/wiki/footgun) that is going to cause you all kinds of surprising problems in the future unless you change it to a meaningful name. It's also a bad idea to end a class name with `List` if it isn't actually a [`List`](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1). – Dour High Arch Dec 23 '21 at 17:42
  • It shouldn't be adding "`@`" to that identifier in the debugger, but it's innocuous. You can put it on any identifier that's not otherwise a keyword and it has no effect. That happens a lot in Razor views because `@class` is common and people think they have to do it on every attribute name in the anonymous object. – madreflection Dec 23 '21 at 17:51
  • I am using a third party API and their schema requires the fields be named with "name" and "type". I would have chosen another name though – Hernan Z Dec 23 '21 at 18:30
  • 1
    When you say that, do you mean you're sending some json to a server owned by someone else, and it's expecting your attributes to say `name` and `type` ... I ask because usually there's a way to have the name you want in C# but have it serialize as something else, e.g. decorating the property with `[JsonProperty("name")] public string RecordFeatureName {get;set;}`. Ultimately you shouldn't have to sacrifice reasonable C# coding standards/conventions for the sake of some API's attribute naming insistence – Caius Jard Dec 23 '21 at 18:59

0 Answers0