Guruji Point - Code You Want To Write

  • Home
  • Asp.Net
  • WCF
  • SQL
  • Type Script
  • AngularJS
  • Tech News
  • Blog
  • Earn Online

Saturday, 28 October 2017

Arrange Distinct Elements Of A List In Ascending Order Using LINQ

 arrange list in ascending order using LINQ, asp.net, Asp.Net C#, aspnetc#, csharp, guruji point, Gurujipoint     No comments   


Introduction
In this article we will learn how to arrange the distinct element of a List in ascending orde using LINQ. LINQ example to arrange the list element in C#.

Previous Updates
In previous articles we have learnt  Maintain state of dynamic added userConrol in asp.net using c#. Insert Only Numeric values in Asp Textbox using Regex. 

Description:
Here i am using the List collection to store the temporary/static data. In your case it might be the database data. GetItems function gets all the static data with in Items class. 
Remove Special Character from a String using Regex

class Program
{
static void Main(string[] args)
{
    var itemlist = (from c in Items.GetItems()
                    select c.ItemDes)
               .Distinct()
               .OrderBy(x => x);

    foreach (var item in itemlist)
    Console.WriteLine(item);
    Console.ReadLine();
}
class Items
{
    public int ItemId { get; set; }
    public string ItemDes { get; set; }

    public static List<Items> GetItems()
    {
        List<Items> itemlist = new List<Items>();
        itemlist.Add(new Items() { ItemId = 1, ItemDes = "Brother" });
        itemlist.Add(new Items() { ItemId = 2, ItemDes = "Jackson" });
        itemlist.Add(new Items() { ItemId = 3, ItemDes = "PointGuruji" });
        itemlist.Add(new Items() { ItemId = 4, ItemDes = "GurujiPoint " });
        itemlist.Add(new Items() { ItemId = 5, ItemDes = "Honey" });
        itemlist.Add(new Items() { ItemId = 6, ItemDes = "Biscuit" });
        return itemlist;
    }
  }
 }

Remove unwanted character from a string Using LINQ

OUTPUT:
Biscuit
Brother
GurujiPoint
Honey
Jackson
PointGuruji
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home
View mobile version

0 comments:

Post a Comment

Facebook Updates

Guruji Point

Categories

Comman table Expression in SQL Dynamic Grid Row IQueryable in c# Learn AngularJS Scope_Identity() Use of indexes comma seperated string in sql row_number() and dense_rank() salary table structure. while loop in sql why do we need cursor why tuple used

About Us

This blog is about the Programming ,Tech News and some intresting facts related Contents. Here you can find fundamental and expert level topic of programming languages very practically related to C# , Asp.Net ,Sql-Server, JavaScript, Jquery, WebServices And also Web-Api, WCF ,WPF, Angular Js.

Contact Us

Email Us - gurujipoints@gmail.com
Contact- 8077657477

Reach Us

Copyright © Guruji Point - Code You Want To Write