Recently I was facing with a json object name declaration inside class and was able to resolve it with following:
[JsonProperty("flv-270p")]
public string flv270p { get; set; }
So If I want to declare flv-270p without JsonProperty how shall I do it?
like :
public string flv270-p { get; set; }
Short answer: you can't.
.NET supports arbitrary member names, including those illegal in CIL languages. However if a language does not support it then you cannot use it, and this includes hyphens and dashes. Auto-properties in C# use <
and >
in their hidden backing field names for this reason.
C# does let you prefix keywords with the @
symbol to allow you to use it as a variable or member name (e.g. public int @class
or public void @struct(int @interface)
but this is for the benefit of consumers.
However c# does not let you use hyphens in names under any circumstances because that character is used for the unary negation and binary subtraction sub operator. A name flv270-p
is interpreted as "flv270
minus p
".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With