I've written a class definition like
public class Item
{
public double? 30dhi { get; set; }
public double? 30dlo { get; set; }
public double? 7dhi { get; set; }
public double? 7dlo { get; set; }
}
Why it's not allowing me to add properties having alphanumeric keys The error is like below
invalid token '30d' for class , struct or interface member declaration
Why it's not allowing me to add properties having alphanumeric keys
A property name has to be an identifier. Identifiers in C# can't start with a digit. You can have a digit after the first character, but not as the first character.
See section 2.4.2 of the C# 5 specification for the precise details of what is allowed for an identifier. The full grammar is too long to post here usefully, but the crucial part is:
identifier-or-keyword:
identifier-start-character identifier-part-charactersoptidentifier-start-character:
letter-character
_ (the underscore character U+005F)identifier-part-characters:
identifier-part-character
identifier-part-characters identifier-part-characteridentifier-part-character:
letter-character
decimal-digit-character
connecting-character
combining-character
formatting-characterletter-character:
A Unicode character of classes Lu, Ll, Lt, Lm, Lo, or Nl
A unicode-escape-sequence representing a character of classes Lu, Ll, Lt, Lm, Lo, or Nl
Note that the example of 30d
is a great one for why it's not allowed - that's actually a numeric literal, of the value 30 and type double
. (You've actually got 30dhi
of course, but the parser has parsed 30d
as a token.)
See more on this question at Stackoverflow