Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I do have a doubt on the syntax and methods written in a format I......<>

Ex: IEnumerable<report>

My question is, When and where we use these type of syntax and what are they and it's uses?

Can you please elaborate on this?

[edit]HTML encoded - OriginalGriff[/edit]
Posted
Updated 4-Jan-16 21:20pm
v2
Comments
Tomas Takac 5-Jan-16 3:16am    
Are you referring to generic type inference? It would help if you provide an code sample to illustrate the problem (via Improve question).
Philippe Mori 5-Jan-16 19:51pm    
Read a book on C# first...

That (angled brackets; <>) is "generic", not LINQ. They are two entirely separate things.

I can see, what made you confuse yourself, the result of a LINQ operation.

C#
using System.Linq;

// This is generic
var aCollection = new List<int> { 1, 2, 3, 4, 5 };

// This is LINQ
var result = from item in aCollection
             // where (if required)
             select item;
</int>


Generic is used to pass a type as a parameter, not just a variable or object. By passing a type, I mean, that you can instruct the compiler, either to create a list of integers or string items and so on.

C#
var intList = new List<int> { 1, 2, 3 };
var stringList = new List<string> { "Hello", "World" };
</string></int>


LINQ on the other hand is a "very powerful" feature of C# (and VB.NET). The concept (and query building) is very much similar to SQL. You first select a data source, then you perform the operations on it to get a collection (or a single item). For example, the code above. A short answer summary cannot sum up the "pros and cons", so, please read the guides and the articles attached below.

LINQ (Language-Integrated Query)[^]
System.Collections.Generic Namespace[^]

CodeProject articles:
A Look at LINQ[^]
LINQ to Life[^]
LINQ FAQ for Newbies[^]
Generics <C#>[^]
Generics in C# 2.0[^]
 
Share this answer
 
Comments
Per Söderlund 6-Jan-16 2:20am    
Well said and easy to understand (easy is a relative term). Good answer.
They are not Linq specifically, they are called Generics and they are a way to write a class, interface, or method which can work with many different class types without having to code for each possible class at design time. Generics were introduced in .NET V2.0 with VS2005, and Ling wasn't available until V3.0 in VS2008.

See here: MSDN: Generics[^] as it's far too big a subject to explain in any detail in a little textbox like this! :laugh:
 
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