Click here to Skip to main content
11,704,001 members (67,400 online)
Rate this: bad
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
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.
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!
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 Maciej Los 530
1 OriginalGriff 510
2 Sergey Alexandrovich Kryukov 421
3 Andy Lanng 294
4 F-ES Sitecore 220
0 OriginalGriff 8,744
1 Sergey Alexandrovich Kryukov 7,747
2 CPallini 5,107
3 Maciej Los 4,716
4 Mika Wendelius 3,606

Advertise | Privacy | Mobile
Web02 | 2.8.150819.1 | Last Updated 3 Dec 2012
Copyright © CodeProject, 1999-2015
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