Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication4
  8. {
  9.     class Program
  10.     {      
  11.         public List<int> prepareListOfValues()
  12.         {
  13.             List<int> list = new List<int>();
  14.             for (int i = 0; i < 10; i++)
  15.             {
  16.                 list.Add(i);
  17.             }
  18.             return list;
  19.         }
  20.  
  21.         //LAMBDA
  22.         public void LambdaExpression()
  23.         {
  24.             var result = from r in
  25.                              Enumerable.Range(1, 10).Where(num => num % 2 == 0)
  26.                          select r;
  27.             foreach (var r in result)
  28.             Console.WriteLine(r);
  29.             Console.ReadKey(true);
  30.         }
  31.  
  32.         //metoda anonimowa
  33.         public void AnonymouMethod()
  34.         {
  35.             var result = from r in
  36.             Enumerable.Range(1, 10).Where(delegate(int number)
  37.              {
  38.              if (number % 2 == 0)
  39.                  return true;
  40.                  return false;
  41.              })
  42.             select r;
  43.             foreach (var r in result)
  44.             Console.WriteLine(r);
  45.             Console.ReadKey(true);
  46.         }
  47.  
  48.  
  49.         //predicate
  50.         public void Predicate()
  51.         {
  52.              var result = from r in
  53.                      Enumerable.Range(1, 10).Where(GetOdd)
  54.                      select r;
  55.             foreach (var r in result)
  56.             Console.WriteLine(r);
  57.             Console.ReadKey(true);
  58.         }
  59.         static bool GetOdd(int number)
  60.         {
  61.             if (number % 2 == 0)
  62.                 return true;
  63.             else
  64.                 return false;
  65.         }
  66.  
  67.         static void Main(string[] args)
  68.         {
  69.             Program pr = new Program();
  70.             pr.LambdaExpression();
  71.             pr.AnonymouMethod();
  72.             pr.Predicate();
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement