.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> LINQ >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Ascending and Descending GenericList using LINQ

Posted By:Syed Shakeer Hussain       Posted Date: December 19, 2011    Points: 40    Category: LINQ    URL: http://www.dotnetspark.com  

Following code shows you how to Sort the GenericList in Ascending and Descending using LINQ
 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Collections;

namespace LinQSamples

{

    class Program

    {

        static void Main(string[] args)

        {  GenericListMethod();

            Console.Read();

        }

         public static void GenericListMethod()

        {

           Console.WriteLine("\nAsecnding GenericList Using Linq");

            Console.WriteLine("--------------------");

            var Asecnding = from sl in li

                           orderby li ascending

                           select sl;

            foreach (int j in Asecnding)

            {

                Console.WriteLine("{0}", j);

            }

        

Console.WriteLine("\nAscending GenericList MethodII Using Linq");

            Console.WriteLine("--------------------");

            var z = from j in li.OrderBy((y => y))

                    select j;

            foreach (var item in z)

            {

                Console.WriteLine("{0}", item);

            }


            Console.WriteLine("\nDescending GenericList Using Linq");

            Console.WriteLine("--------------------");

            var Descending = from sl in li

                           orderby li descending

                           select sl;

            foreach (int k in Descending)

            {

                Console.WriteLine("{0}", k);

            }

           

 

            Console.WriteLine("\nDescending GenericList MethodII Using Linq");

            Console.WriteLine("--------------------");

            var q=from j in li.OrderByDescending(y=>y)

                  select j;

 

            foreach (var item in q)

            {

                Console.WriteLine("{0}",item );

            }

    }

}



     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend