Click here to Skip to main content
11,798,866 members (74,506 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 CPallini 505
1 OriginalGriff 503
2 Richard MacCutchan 321
3 Maciej Los 245
4 phil.o 244
0 OriginalGriff 2,270
1 Maciej Los 1,810
2 KrunalRohit 1,496
3 CPallini 1,425
4 Richard MacCutchan 1,109

Advertise | Privacy | Mobile
Web02 | 2.8.151002.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