Finding Odd numbers from a Range of Number using LINQ in C#

If we have a range of number from 1 to 20 and we want to find odd among them using LINQ . We have three options for that 1. Calling a Predicate 2. Anonymous Method 3. Lambda So here we can see that we need to pass a predicate to evaluate the condition. Calling aContinueContinue reading “Finding Odd numbers from a Range of Number using LINQ in C#”

Using Lambda expression in FindAll()

I got a critical comment from @amazedsaint. You can read his blog http://amazedsaint.blogspot.com/ If you read my previous post http://dhananjaykumar.net/2010/10/01/findall-finding-multiple-items-in-c-list/ , I am using a method GreaterThanHun As predicate to pass as parameter to FindAll() Instead of that we can use 1. Anonymous method 2. Lambda expression So, I am going to show you hereContinueContinue reading “Using Lambda expression in FindAll()”

FindAll() : Finding multiple items in C# List

Let us say we have a list of integer and we want to find all the number greater than 100. If list is as follow List<int> lst = new List<int>();             lst.Add(20);             lst.Add(300);             lst.Add(400);             lst.Add(9);             lst.Add(19);             lst.Add(789);    ContinueContinue reading “FindAll() : Finding multiple items in C# List”

Inserting element in sorted Generic list (List) using binary search in C#

I got a mail asking, “How we could insert an item in sorted generic list such that after insertion list would be remaining sorted?” Answer of this is using Binary Search As we know Binary search works on Divide and conquer algorithm. And running time using Binary search is very efficient. So we need toContinueContinue reading “Inserting element in sorted Generic list (List) using binary search in C#”

Sorting a Generic List in C#

Objective This article will give code snippet on how to sort a generic list in C# I have a class called Product Product.cs class Product     {         public string ProductName { get; set; }         public int ProductPrice { get; set; }     } And List of Product as below,  List<Product> prdListContinueContinue reading “Sorting a Generic List in C#”

Delegate to Lambda Expression

Objective This article will not give any theoretical definition of 1. Delegate Read theory of Delegate here 2. Anonymous method 3. Lambda Expression Read theory of Lambda expression here I am going to give a story type discussion from Delegate to Lambda expression. Let us say, there is a requirement that you need to passContinueContinue reading “Delegate to Lambda Expression”

Anonymous types in C# 3.0

1. Anonymous types are new feature being added in C# 3.0. 2. These are data types being generated on the fly at the run time. 3. These data types are generated through complier rather than explicit class definition. Program.cs using System;using System.Collections.Generic;using System.Linq;using System.Text; namespace ConsoleApplication17{    class Program    {        static void Main(string[] args)        {    ContinueContinue reading “Anonymous types in C# 3.0”

Collection initializer in C# 3.0

1. Collection initializer is new feature of C# 3.0 2. Collection initializer gives a simple syntax to create instance of a collection. 3. Any object that is implementing System.Collections.Generic.ICollection<T> can be initialized with collection initializer. Let us say, we have a class Student.cs public  class Student     {        public string FirstName { get;ContinueContinue reading “Collection initializer in C# 3.0”

7 queries on LINQ to SQL class

 In this article, I am going to show you how we can perform various operations using LINQ to SQL. Database description Let us say, I have created a database called ILPTrainee. This table got only one table with below structure EmpId is primary key here. For our explanation, I have put few records in theContinueContinue reading “7 queries on LINQ to SQL class”