Click here to Skip to main content
15,891,926 members
Please Sign up or sign in to vote.
4.75/5 (4 votes)
See more:
Could anyone please tell me what the meaning of the ` character is in the stack trace as shown below ?

at System.ComponentModel.BindingList`1.get_ItemTypeHasDefaultConstructor()
at System.ComponentModel.BindingList`1.Initialize()
at System.ComponentModel.BindingList`1..ctor() 

I have been searching but could not find an explanation.

Thanks,
Arwin van der Laan
Posted

The reason beghind it is a little complicated, but the reason is that BindingList is generic. Take the example
C#
BindingList <int> foo;
BindingList <string> bar;

At Compile Time the class name is appended with a number for each generic type. Your class has one generic so type so it has `1 after it. A kind of place-holder is left for the actual type. This is because the type cannot be known until runtime, for example the generic can be instaniated by reflection
At runtime the framework generates a class for each specified type in the generic. This is when the substitution of the place-holders for the type is made.

Once defined at runtime, every BindingList <int> will become a BindingList`1.
C#
Dictionary <string, string> baz;

Will be compiled to Dictionary`1`2

Once a runtime List type is generated for a specific type e.g. int, it will be re-used for other List<int>s.

See this for fuller (and hopefully clearer explanation):
http://www.artima.com/intv/generics2.html[^]
Very godd question BTW, most people don't notice.

KPB: Corrected grave factual errors - apologies for the confusion. I'm not sure what I was on yesterday, but a good night's sleep seems to have helped!
 
Share this answer
 
v5
Comments
Daniel Grunwald 28-Oct-10 16:26pm    
This explanation is incorrect.
The number is generated at COMPILE TIME.
Both List<string> and List<int> will use the class List`1. The `1 is simply appended by the compiler to disambiguate the class name (because C# allows having both List<t> and List<t,s> in the same namespace)
Daniel Grunwald 28-Oct-10 16:27pm    
This explanation is incorrect.
The number is generated at COMPILE TIME.
Both List<string> and List<int> will use the class List`1. The `1 is simply appended by the compiler to disambiguate the class name (because C# allows having both List<T> and List<T,S> in the same namespace). It merely indicates the number of type parameters.
Keith Barrow 28-Oct-10 16:47pm    
@No, they won't both compile down to List`1, that wouldn't disambiguate. Secondly, Anders Hejlsberg would tend to disagree with you that my answer is wrong about compile time. He should know, he was responsible for generics in C#.
Keith Barrow 28-Oct-10 16:49pm    
I quote: "The IL and metadata contains additional information that knows there's a type parameter ..... At *runtime*, when your application makes its first reference to List<int>, the system looks to see if anyone already asked for List<int>.
Keith Barrow 28-Oct-10 16:50pm    
If not, it feeds into the JIT the IL and metadata for List<T> and the type argument int. The JITer, in the process of JITing the IL, also substitutes the type parameter.
Keith, thank you very much.
As soon as I knew the answere it sounded very logical but to trace one character back to the principle you explained didn't cross my mind.
Even a search on MSDN did not come up with your answere but all kinds of irrelevant information.

So :thumbsup::thumbsup::thumbsup::thumbsup::thumbsup:
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900