Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0 C#3.0 C# ASP.NET C#4.0
I doubt whethe it has limited length? Once I named a file called AutoCalculateFileInfoLengthLimit, about 30 charts.
Posted 3-Dec-12 1:20am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Technically, there isn't one - the CLI does not impose any limit, neither does the C# specification.
However, in practice, the C# compiler does impose a limit of 511 characters per name.
If you declare something with 511 characters you are fine, 512 and you will get an "Identifier to long" error.
  Permalink  
Comments
PEIYANGXINQU at 3-Dec-12 7:45am
   
Some one say that the limit is 256, because of 8 bit and 2^8=256
OriginalGriff at 3-Dec-12 8:25am
   
They are wrong - try it!
class
abcdefghijabcdefghijabcdefghijabcdefghij...
{}
and compile - 511 will work, 512 will not.
PEIYANGXINQU at 3-Dec-12 7:49am
   
Can you tell me why is 512? Thank you!
OriginalGriff at 3-Dec-12 8:27am
   
There probably is no reason - other than "I need to know how big the largest one is so I can assign enough buffer space" when they wrote the compiler.
To be honest, you will have run out of readable code a very, very, very long time before you run out of characters in identifiers! :laugh:
RaisKazi at 3-Dec-12 15:05pm
   
Interesting discusion. 5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 434
1 Nirav Prabtani 338
2 Abhinav S 170
3 PIEBALDconsult 160
4 Dave Kreskowiak 155
0 OriginalGriff 7,640
1 Sergey Alexandrovich Kryukov 6,836
2 Maciej Los 3,919
3 Peter Leow 3,698
4 CHill60 2,742


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 3 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100