diff --git a/Linq/Linq-08.linq b/Linq/Linq-08.linq index 64d4ba2..e8530dc 100644 --- a/Linq/Linq-08.linq +++ b/Linq/Linq-08.linq @@ -21,8 +21,6 @@ void Main() shortNames.Dump(); } -public delegate bool IntegerFilter(int i); - public static class ExtensionsMethods { public static List Filter(this List items, Func filter) diff --git a/Linq/Linq-10.linq b/Linq/Linq-10.linq deleted file mode 100644 index 90d6ea5..0000000 --- a/Linq/Linq-10.linq +++ /dev/null @@ -1,153 +0,0 @@ - - -//10- Let's write Linq method FirstOrDefault. - -//Jon Skeet reimplemented Linq to Objects in an entire series. - -//https://codeblog.jonskeet.uk/2010/09/03/reimplementing-linq-to-objects-part-1-introduction/ - -//If you want to master Linq, read the series and implent it on your own. -void Main() -{ - List numbers = new List() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; - - var doubleNumbers = numbers.Select(n => n * 2); //IEumerable -> IEnumerable - - var persons2 = numbers.LinqSelect(n => new Person(n)); //IEumerable -> IEnumerable - - //PROJECTION - - foreach(var person in persons2) - { - Console.WriteLine(person); - } - - //SELECT -> There are two types. - - //numbers.LinqFirstOrDefault().Dump(); -} - -public class Person -{ - public int Number { get; set;} - - public Person(int number) - { - Number = number; - } - - public override string ToString() - { - return $"Person-{Number}"; - } -} - -// - -public delegate string MyDelegateName(int i); //Specifiy definiition - -public delegate TResult MyDelegateName(TInput i); - -public delegate TResult FuncX(T i); - -//public delegate MyDelegateName -//{ -// i = int -// output = void -//} - - -//public struct - -public class IntQueue -{ - private List _items = new List(); - - public void Enqueue(int i) - { - } - - public int Dequeue() - { - return 0; - } -} - - - -//name of generic type that you want to use. - -public class Queue -{ - private List _items = new List(); - - public void Enqueue(T i) - { - - } - - public T Dequeue() - { - throw new NotImplementedException(); - } -} - - - -public delegate Person IntToPersonDelegate(int i); -public delegate int DoubleIntDelegate(int i); - -public delegate TResult IntToX(int i); - - - -public Person GetPersonFromInt(int i) -{ - return new Person(i); -} - - -public int GetDouble(int i) -{ - return i * 2; -} - - -public delegate bool IntegerFilter(int i); - -public static class ExtensionsMethods -{ - //Does everyone understand it fully? - //Let's write SELECT ourselves. - public static IEnumerable Filter(this IEnumerable items, Func filter) - { - foreach (var item in items) - { - if (filter(item)) - yield return item; - } - } - - public static IEnumerable LinqSelect(this IEnumerable source, Func map) - { - foreach(var item in source) - { - yield return map(item); - } - } - - - //Let's implement the default SingleORDefualt and then implement - //a better SingleOrDefault that you can use everywhere. - public static T LinqSingleOrDefault(this IEnumerable items) - { - throw new NotImplementedException(); - } - - //Correct implementation using C# local functions. - public static T BetterFirstOrDefault(this IEnumerable items) - { - throw new NotImplementedException(); - } - -} \ No newline at end of file