Azurewrath

Hi all,

I am wondering what's the name of this operators <> in this context:

List<int> integers = new List<int> ( );

[] is index operators, for arrays, collections, right




Thanks,
Aw


Re: Visual C# Language What's this operator called?

Peter Ritchie

That's not an operator, the angle brackets simply denote type parameters for a type or method.






Re: Visual C# Language What's this operator called?

Azurewrath

Thanks Peter. The reason they are chosen was because () or [] wouldn't be suitable, right (int) would mean casting, maybe that's why they used <>. When I first saw it, it looked kind of strange to see <>, that's why I asked.




Thanks,
Aw




Re: Visual C# Language What's this operator called?

Peter Ritchie

The angle brackets where chosen, in part, because they weren't syntactically correct prior to Generics so they weren't breaking code. i.e there could be no code that existed that used angle brackets in that way.

I imagine angle brackets were chosen because angle brackets were used in C++ for templates; but I couldn't confirm that.






Re: Visual C# Language What's this operator called?

Azurewrath

Thanks Peter. So you are saying, they chose it because no other code was using it but it wasn't correct before generics If so, what happened after generics that made it correct




Thanks,
Aw




Re: Visual C# Language What's this operator called?

Peter Ritchie

In Visual C# 2003 this will not compile:

Code Block

public class MyClass<T>

{

private T value;

}

In Visual C# 2005, Generics were added. This included C# language syntax to support generics (e.g. the angle brackets), so the above became legal C# and now compiles without error.






Re: Visual C# Language What's this operator called?

Azurewrath

So, in VS 2003, there were no Lists If there was, how they were written




Thanks,
Aw




Re: Visual C# Language What's this operator called?

IsshouFuuraibou

Because VS2003 was tied to .net 1.1 (it really is because of 1.1 not just VS 2003) there were no generics, if you wanted an expandable list you either use the generalized ArrayList (List of the Object type) or you made your own collection classes or managed your typed list and dealt with expanding the static array when needed.





Re: Visual C# Language What's this operator called?

Azurewrath

Thanks alot man!



Aw