2

I tried to create a Controller class with the name 1BigController, but MVC won't let me do that. It changes the controller name to _BigController.

Why can't I start a controller name with a number?

George Stocker
  • 57,289
  • 29
  • 176
  • 237

4 Answers4

5

This is a convention of all C# classes, not just MVC. You can find more in the C# Language Specification (item 2.4.2)

Here's a similar question regarding variable names and numeric vals

Why can't variable names start with numbers?

Community
  • 1
  • 1
Marcus Shockley
  • 310
  • 2
  • 6
1

It could be because you can't have class names that start with a number. I used to program PLC's and the software we used wouldn't allow us to start any tag names with a number. I don't know why we couldn't other then that was the rule.

0

MVC uses a convention approach to type resolution. A controller name such as "Big" will cause MVC to search for a BigController. Likewise, if it was not sanitised as "_" and instead was "1Big", MVC would attempt to find a type called 1BigController. Type names cannot start with numbers, so it gets sanitised for you.

Matthew Abbott
  • 60,571
  • 9
  • 104
  • 129
0

Variable names have to start with a letter or underscore. The remaining characters can be letters, underscores, or digits. I am not sure why this is the convention, but it has been for a long time.

Peter Olson
  • 139,199
  • 49
  • 202
  • 242