Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication4
- {
- class Program
- {
- public List<int> prepareListOfValues()
- {
- List<int> list = new List<int>();
- for (int i = 0; i < 10; i++)
- {
- list.Add(i);
- }
- return list;
- }
- //LAMBDA
- public void LambdaExpression()
- {
- var result = from r in
- Enumerable.Range(1, 10).Where(num => num % 2 == 0)
- select r;
- foreach (var r in result)
- Console.WriteLine(r);
- Console.ReadKey(true);
- }
- //metoda anonimowa
- public void AnonymouMethod()
- {
- var result = from r in
- Enumerable.Range(1, 10).Where(delegate(int number)
- {
- if (number % 2 == 0)
- return true;
- return false;
- })
- select r;
- foreach (var r in result)
- Console.WriteLine(r);
- Console.ReadKey(true);
- }
- //predicate
- public void Predicate()
- {
- var result = from r in
- Enumerable.Range(1, 10).Where(GetOdd)
- select r;
- foreach (var r in result)
- Console.WriteLine(r);
- Console.ReadKey(true);
- }
- static bool GetOdd(int number)
- {
- if (number % 2 == 0)
- return true;
- else
- return false;
- }
- static void Main(string[] args)
- {
- Program pr = new Program();
- pr.LambdaExpression();
- pr.AnonymouMethod();
- pr.Predicate();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement