advantages on LINQ

  • Thread starter Thread starter thirumurugan.ga
  • Start date Start date
I want to know advantages on LINQ

That's a very vague question.

For one, you got a simplified syntax for querying enumerable data
sources of various types.
 
As Lasse says, that is a vague question, but there are some definite
advantages that can be pointed to.

The biggest one is that you can now structure queries in your code which
are compile-time checked, regardless of the back end data source (so if you
are using LINQ-to-SQL, then you are going to get compile-time checking on
your queries, instead of seeing it at runtime with a query string).

If you are using LINQ-to-Objects, then a big advantage is that you can
create complex queries in a simple manner which were previously very
difficult.

For example, say you want to get all the declared methods on a type
which are generic which you want to run some processing on. In .NET 2.0,
you would do this:

// Get the methods. Assume type is of type Type.
IEnumerable<MethodInfo> methods = type.GetMethods();

// Cycle.
foreach (MethodInfo methodInfo in methods)
{
// Check to see if the method is generic.
if (methodInfo.IsGeneric)
{
// Continue processing.
}
}

In .NET 3.5/C# 3.0, you can do this:

// Generate the query.
IEnumerable<MethodInfo> methods =
from methodInfo in type.GetMethods()
where methodInfo.IsGeneric
select methodInfo;

// Process the methods.
foreach (MethodInfo methodInfo in methods)
{
// Process.
}

Subsequently, you could also do this, which is even simpler, in my
opinion:

// Get the methods.
IEnumerable<MethodInfo> methods = type.GetMethods().Where(methodInfo =>
methodInfo.IsGeneric);

// Process.
foreach (MethodInfo methodInfo in methods)
{
// Process.
}

Two big wins, IMO.
 
In .NET 3.5/C# 3.0, you can do this:
// Generate the query.
IEnumerable<MethodInfo> methods =
from methodInfo in type.GetMethods()
where methodInfo.IsGeneric
select methodInfo;

// Process the methods.
foreach (MethodInfo methodInfo in methods)
{
// Process.
}

Subsequently, you could also do this, which is even simpler, in my
opinion:

// Get the methods.
IEnumerable<MethodInfo> methods = type.GetMethods().Where(methodInfo =>
methodInfo.IsGeneric);

// Process.
foreach (MethodInfo methodInfo in methods)
{
// Process.
}

Two big wins, IMO.

Man, I wish I was working for a company that allowed me to use .Net
3.5/C#3.0. Currently, we are still using the 1.1 framework and VB.Net...(I
know C# and VB.Net but they won't allow us to use C#).

Sucks for me!

:)

Mythran
 
Mythran said:
Sucks for me!

:)

Mythran

GROUPHUG!

I feel so sorry for you...
Maybe you should quit your job and find a better employer?

- Michael Starberg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top