Friday, September 23, 2011

LINQ WITH DELEGATES CONCEPTS

Normal query string:
===================

static void Main(string[] args)
        {
            string[] names = { "chitharans", "naga", "ravi", "praveen", "chith", "hello", "welcome" };
            IEnumerable<string> query123 = from sss in names where sss.Length >= 4 orderby sss descending  select sss.ToUpper();
            foreach (string item in query123)
                Console.WriteLine(item);
            Console.ReadKey();
        }


Funtion  using query string:
=========================================

  static void Main(string[] args)
        {
            string[] names = { "chitharans", "naga", "ravi", "praveen", "chith", "hello", "welcome" };
            Func<string, bool> one = sss => sss.Length >= 4;
            Func<string, string> two = sss => sss;
            Func<string, string> three = sss => sss.ToUpper();
            IEnumerable<string> query123 = names.Where(one).OrderBy(two).Select(three);
          
            foreach (string item in query123)
                Console.WriteLine(item);
            Console.ReadKey();
        }

Delegates using query string:
============================

 static void Main(string[] args)
        {
            string[] names = { "chitharans", "naga", "ravi", "praveen", "chith", "hello", "welcome" };
            Func<string, bool> one = delegate(string sss)
            {
                return sss.Length>=4;
            };
            Func<string, string> two = delegate(string sss)
            {
                return sss;
            };
            Func<string, string> three = delegate(string sss)
            {
                return sss.ToUpper();
            };



           
            IEnumerable<string> query123 = names.Where(one).OrderBy(two).Select(three);
         
            foreach (string item in query123)
                Console.WriteLine(item);
            Console.ReadKey();
        }

No comments:

Post a Comment