Created
January 23, 2022 10:47
-
-
Save golf1052/064c59e036fb18a000364295ad6a1bc2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
var mapResult = new string[] {"π", "π", "π", "π"}.Select(e => "πΆ"); | |
PrintEnumerable(mapResult); | |
var filterResult = new string[] {"π", "πΆ", "π", "π"}.Where(e => e == "πΆ"); | |
PrintEnumerable(filterResult); | |
var everyResult = new string[] {"π", "π", "πΆ", "π"}.All(e => e == "πΆ"); | |
Console.WriteLine(everyResult); | |
var someResult = new string[] {"π", "πΆ", "πΆ", "π"}.Any(e => e == "πΆ"); | |
Console.WriteLine(someResult); | |
var fillResult = new string[] {"π", "π", "π", "π"}.Select((e, i) => i > 0 ? "πΆ" : e); | |
PrintEnumerable(fillResult); | |
var findIndexResult = new string[] {"π", "π", "πΆ", "π"}.TakeWhile(e => e != "πΆ").Count(); | |
Console.WriteLine(findIndexResult); | |
var findResult = new string[] {"π", "πΆ", "π", "π"}.First(e => e == "πΆ"); | |
Console.WriteLine(findResult); | |
var reduceResult = new string[] {"π₯", "π ", "π", "π§"}.Aggregate((acc, cur) => $"{acc}{cur}"); // you can't actually turn these four emoji into π | |
Console.WriteLine(reduceResult); | |
} | |
public static void PrintEnumerable(IEnumerable<string> arr) | |
{ | |
Console.WriteLine(string.Join("", arr)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment