They usually involve generics. But some methods with generics don't have them, and not all extension methods have them.
They've just "been there" since day one, we've all seen them; but I realized I still don't know what they mean, and I can't find the answer anywhere. Now it's really bugging me. Google just turns up results that are about XML, etc.
Is this officially documented anywhere? Thanks.
EDIT: Well that's just great. Since I just created an account to make my first Stack Overflow post, to get an answer for this burning question; I'm not allowed to post my pretty Intellisense picture, or create a new tag "angle-brackets". I love Stack Overflow, but... what a welcome!
Maybe my problem is that they aren't actually called "angle brackets"... ??
Anyway, I guess if you really want to see my beautiful screenshot you could manually go to:
Distinct>< http://www.freeimagehosting.net/uploads/6a6c2f3268.png
Bump me up please so I can include it in the post, thanks. ;)
In c#, generics are represented by using angle bracket <>. To define a class or method as generic, we need to use a type parameter as a placeholder with angle (<>) brackets. The compiler will replace all the placeholders with the specified type at compile time.
The angle bracket (< or >), which is also called an “inequality sign” for its use in mathematics, is a kind of sideways caret that can be used to include tags or pieces of code. This ASCII set of characters is common in web design and other types of coding projects.
These methods are generic.
However, the compiler automatically infers the generic type parameter from the method call, so you don't need to use the brackets when calling the method.
For example, if you have an IEnumerable<int> myNumbers
, the following four statements are equivalent:
myNumbers.Count();
myNumbers.Count<int>();
Enumerable.Count(myNumbers);
Enumerable.Count<int>(myNumbers);
In the first and third calls, the compiler infers the int
parameter because myNumbers
is an IEnumerable<int>
.
The Count
extension method is declared (in System.Core.Dll) like this:
public static int Count<TSource>(this IEnumerable<TSource> source);
they are for generics. When you use the functions you don't always have to put in the because in many cases the compiler can figure it out by context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With