Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the maximum length of a C#/CLI identifier?

Which other restrictions are there on names (beside the obvious uniqueness within a scope)?

Where are those defined?

like image 720
David Schmitt Avatar asked Oct 09 '08 09:10

David Schmitt


People also ask

What is the maximum length of identifiers in C?

Microsoft Specific Although ANSI allows 6 significant characters in external identifier names and 31 for names of internal (within a function) identifiers, the Microsoft C compiler allows 247 characters in an internal or external identifier name.

What is the maximum length?

Maximum Length means the largest total length of a species or species group that may be legally possessed, measured from the tip of the snout to the end of the tail.

What is the maximum length of AC string C++?

Long answer: There's a hard limit based on the size of size_t . Most implementations have size_t as 32 bits, so that means the max is 232 - 1 or 4294967295 characters.

What is the maximum length of C string Mcq?

10) What is the maximum length of a C String.? Explanation: Maximum size of a C String is dependent on implemented PC memory. C does not restrict C array size or String Length.


2 Answers

From the PDF of ECMA-335, Partition II, section 22:

Metadata preserves name strings, as created by a compiler or code generator, unchanged. Essentially, it treats each string as an opaque blob. In particular, it preserves case. The CLI imposes no limit on the length of names stored in metadata and subsequently processed by the CLI

If I've read this correctly and the context is correct then there's no actual limit to the length of an identifier in the CLR.

like image 33
Rob Avatar answered Sep 30 '22 21:09

Rob


In addition to the other answers, the maximum identifier length that is accepted by the Microsoft Visual C# compiler is 511 characters. This can be tested with the following code:

class Program {     private static void Main(string[] args)     {         int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 5;     } } 

The length of the variable name there is 511 characters. This code compiles, but if one character is added to the name, the compiler outputs error CS0645: Identifier too long.

like image 135
qwertium Avatar answered Sep 30 '22 20:09

qwertium