lunedì 10 giugno 2013

How To: Linq Sort / OrderBy

Facendo qualche esperimento mi sono reso conto che l'order by di Linq è meno scomodo di quanto si possa pensare.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestSort
{
    class Program
    {
        static void Main(string[] args)
        {
            entities es = new entities();
            es.Add(new entity() { id = 1, 
                                    name = "fabio", 
                                    description = "nice" });

            es.Add(new entity() { id = 2, 
                                    name = "lorenzo", 
                                    description = "very nice" });

            es.Add(new entity() { id = 2, 
                                    name = "federico", 
                                    description = "it will be" });


            var esx = es.OrderBy(c=> c.name);
            
        }
    }


    public class entity
    {
        public int id { get; set; }
        public string name { get; set; }
        public string description { get; set; }
    }

    public class entities : List<entity>
    { 
    
    }
}

Facile.. no ?

Nessun commento: