0

Is there away that i can create property or a variable that has data- as the prefix? (because by default the compiler wont let me!)

abba tat
  • 73
  • 8
  • This ain't possible... your question could be related to this question : [Can you have a property name containing a dash](http://stackoverflow.com/questions/5771577/can-you-have-a-property-name-containing-a-dash) – The_Black_Smurf Feb 07 '16 at 14:31

1 Answers1

2

Short answer: no.
Long answer: according to C# Specification an identifier must start with a letter (capital or lowercase) or underscore. After the first letter it may contains numbers, letters and underscore.
These rules exists because the compiler is not able to recognize if you are declaring a variable (e.g. data-part) or you are trying to accomplish an operation (in this case a subtraction)

Tinwor
  • 7,765
  • 6
  • 35
  • 56
  • `data-` actually starts with a letter, problem is that identifier can not contain `-` symbol. – tchelidze Feb 07 '16 at 14:31
  • @Tinwor i want create a property called attr-name but C# wont let me – abba tat Feb 07 '16 at 14:31
  • You can use [all kinds of random Unicode characters](http://stackoverflow.com/questions/950616/what-characters-are-allowed-in-c-sharp-class-name) if you want, but don't expect it to play nicely with the IDE. In keeping with the standard .NET naming convention, you should call the property `AttrName`, using PascalCase. @abba – Cody Gray - on strike Feb 07 '16 at 15:18