In this post I’m going to explain you about Linq AddRange method. This method is quite useful when you want to add multiple elements to a end of list. Following is a method signature for this.
public void AddRange(
IEnumerable<T> collection
)To Understand let’s take simple example like following.
using...
Showing posts with label LINQ. Show all posts
Showing posts with label LINQ. Show all posts
Tuesday, October 22, 2013
Thursday, June 27, 2013
Deferred vs Immediate execution in Linq
In this post, We are going to learn about Deferred vs Immediate execution in Linq. There an interesting variations how Linq operators executes and in this post we are going to learn both Deferred execution and immediate execution.
What is Deferred Execution?
In the Deferred execution query will be executed and evaluated at the time of query variables usage. Let’s take an example to understand...
Thursday, May 23, 2013
How to sort a data table in C# with LINQ
One of friend today ask how we can sort data table based on particular column? So I thought it’s a good idea to write a blog post about it. In this blog post we learn how we can learn how we can sort database with LINQ queries without writing much more long code. So let’s write a code for that.
using System;
using System.Data;
namespace ConsoleApplication1
{
class Program
{
static...
Saturday, March 23, 2013
Difference between All and Any operator in linq
In this post we are going to learn about difference between ‘All’ and ‘Any’ operator in Linq.
Difference between ‘All’ and ‘Any’ operator:
All operator checks whether all elements have met specific conditions or not while Any operator check whether there is any elements exist in collection or not?
So what we are waiting for Let’s take a example.
using System;
using System.Linq;
namespace...
Saturday, March 16, 2013
All operator in linq
Few days back I came across “All” operator in Linq. I thought it will be good idea to write a blog post about it and share it with community.
All operator in linq:It’s almost similar to select it returns all the element in the input sequence with matching condition in given predicate. Following is syntax for All.
public static bool All<TSource>(
this IEnumerable<TSource> source,
Func<TSource,...
Wednesday, February 13, 2013
How to convert a list into array with Linq
In this post, I am going to explain how we can convert an generic list to simple int array with Help of Linq. Recently, I was working on an application and there I needed an Int array of for list of ids in generic list. I tried various methods and then with the help of ‘Select’ operator and ToArray method I have easily converted an generic list to the int array.
Lets take a simple example. I need...
Friday, February 1, 2013
SelectMany operator in Linq C#
SelectMany is an important operator in Linq. It takes each element of a sequence to an IEnumerable and flattens the resulting sequences into one sequence. You can find out more information about different overload list from the below link.
http://msdn.microsoft.com/en-us/library/system.linq.enumerable.selectmany.aspx
In this post I am going to explain How it can be really useful when you want to...
Friday, January 18, 2013
Linq performance with Count() and Any()
Recently I was using resharper to refactor some of my code and found that it was suggesting to use any() extension method instead of count() method in List<T>. I was really keen about performance and found that resharper was right. There is huge performance difference between any() and count() if you are using count() just to check whether list is empty or not.
Difference between Count()...
Friday, December 21, 2012
Where I can find SQL generated by Linq-To-SQL
Yesterday I have written a blog post about Where I can find SQL Generated by Entity Framework? and same day I got request from one of the our reader Ramesh that how I can find SQL generated by Linq-To-SQL?. I thought its a good idea to write a blog post to share amongst all who need this instead of...
Tuesday, April 17, 2012
Difference between SkipWhile and Where in linq
Before some time I have written a blog post about the SkipWhile operator and a reader of my blog asked me that we can do the same thing with Where also but there is a difference between this two. So In this post I am going to explain you difference between those two.
Where operator filters a list of collection based on condition. It will filter whole collection while SkipWhile will only skip those...
Saturday, April 14, 2012
TakeWhile operator in linq
In this post I am going to explain TakeWhile Operator in details. TakeWhile is one of partitioning operator available in Linq. It will take sequence until condition becomes false.
Here is the example for that.
using System;
using System.Collections.Generic;
using System.Linq;
namespace Linq
{
class Program
{
static void Main(string[] args)
{
int[] numbers ={10,9,8,7,6,5,4,3,2,1};
...
SkipWhile Method in Linq
I have been playing around linq and I have found great method call SkipWhile method. SkipWhile methods skips particular element which matches condition in predicate this can be use full in condition where we need to skip elements on particular condition.
So let’s take some example. I have written following console application code.
using System;
using System.Collections.Generic;
using System.Linq;
namespace...
Wednesday, August 17, 2011
Creating Basic RSS Reader in ASP.NET MVC 3
In this post I am going to explain you how we can create a basic RSS Reader with the help of Linq-To-Xml and ASP.NET MVC3 Razor. Those who are writing or reading Blogs already knows what is RSS Reader. But those who does not know What is RSS. Below is the definition for RSS as per Wikipedia.
RSS...
Sunday, January 9, 2011
Distinct operator in Linq
Linq operator provides great flexibility and easy way of coding. Let’s again take one more example of distinct operator. As name suggest it will find the distinct elements from IEnumerable. Let’s take an example of array in console application and then we will again print array to see is it working...
Sunday, August 29, 2010
LinqDatasource A Great Control for declarative programming
I have used data source control many times and its great it provides us great features for declarative binding. LinqDataSource Control is a great control and it allows us to bind linq queries without writing any code declaratively. Let’s create a example in that example I am not going to write a single...
Tuesday, August 24, 2010
Using Let Keyword in Linq
I am using Linq-To-Object in my current project to remove some extra loops and I have found one of the great keyword in Linq called ‘Let’. Let keyword provides facility to declare a temporary variable inside the Linq Query.We can assign the result of manipulation to temporary variable inside query and...
Wednesday, August 18, 2010
Entity Framework 4.0- Bind Stored Procedure with Result Entity class
Microsoft Entity Framework version 4.0 is a brand new ORM(Object Relational Mapper) from Microsoft. It’s provides now some new features which are not there in the earlier version of Entity framework. Let’s walk through a simple example of a new features which will create a new Entity class based on...
Tuesday, August 3, 2010
Binding A Custom Entity Class to stored procedure using Linq-To-SQL
I have already written several post about Linq its a great ORM that we can use in various way. The purpose of this post to demonstrate How we can bind custom entity to stored procedure result with use of Linq-To-SQL. Let’s go through it and you will realize that how easy it will be to bind a Custom...
Wednesday, June 23, 2010
Range Operator in Linq.
Linq is almost providing all the functionalities and i have found one another great operator called range operator which will return a sequence of integer number from start point to number of count. Here is the signature of range operator in Linq.
public static IEnumerable<int> Range(int...
Saturday, June 19, 2010
Zip operator in Linq with .NET 4.0
Microsoft .NET framework 4.0 is having many features that make developers life very easy. Its also provides some enhancement to Linq also. I just found a great operator called Zip which merge the sequence of two entities. Here is the explanation of Zip Operator from MSDN. “The method merges each element...