Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Conditional linq operators
//Title of this code //Rextester.Program.Main is the entry point for your code. Don't change it. using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { var list = new List<Test>() { new Test(1, 2), new Test(1, 5), new Test(1, 3), new Test(1, 4), new Test(1, 1), new Test(1, 3), new Test(2, 2), new Test(2, 5), new Test(2, 3), new Test(2, 4), new Test(2, 1), new Test(2, 3) }; Console.WriteLine("Orderer by one, then by two"); list.OrderBy(f => f.One).ThenByIf(true, f => f.Two).ToList().ForEach(f => Console.WriteLine(f)); Console.WriteLine("Orderer by one only"); list.OrderBy(f => f.One).ThenByIf(false, f => f.Two).ToList().ForEach(f => Console.WriteLine(f)); } } public class Test { public int One {get; set;} public int Two {get; set;} public Test(int one, int two) { One = one; Two = two; } public override string ToString() { return string.Format("One: {0}, Two: {1}", One, Two); } } public static class Ext { public static IOrderedEnumerable<T> ThenByIf<T, TKey>(this IOrderedEnumerable<T> list, bool predicate, Func<T, TKey> sel) { if(predicate) return list.ThenBy(f => sel(f)); else return list; } } }
run
|
edit
|
history
|
help
0
różne wersje parsowania kwoty i daty (CultureInfo)
Listiteration
10857
HashSet implementation
f
Custom thousand separator
Home work3 finding Min and Max (to theGit)
custom Generic stack Implementation
SVNParse
Random number between 1 - 100 between each value of 10 there will be a differnt message