42. var words = new List<string> { “hello”, “world” }; var upperCaseWords = new List<string>(); foreach (var word in words) { upperCaseWords.Add(word.ToUpper()); }
48. var words = new List<string> {“hello”, “world”}; var wordsWithH = new List<string>(); foreach (var word in words) { if(word.Contains(“h”) wordsWithH.Add(word); }
63. Foo(“mark”, true), Foo(“dave”, false), Foo(“mike”, true) Where Foo(“mark”, true), Foo(“mike”, true) First Foo(“mark”, true)
64. var foos = new List<Foo> { new Foo(“mark”, true), new Foo(“dave”, false), new Foo(“mike”, true) }; var firstSpecialFoo = foos. Where(f => f.HasSpecialFlag()). First());
65. var foos = new List<Foo> { new Foo(“mark”, true), new Foo(“dave”, false), new Foo(“mike”, true) }; var firstSpecialFoo = foos.First(f => f.HasSpecialFlag());
74. public class SomeObject { public SomeObject(string p1, string p2, string p3) { if (p1 == null ) throw new Exception(...); if (p2 == null ) throw new Exception(...); if (p3 == null ) throw new Exception(...); // rest of constructor logic } }
75. public class SomeObject { public SomeObject(string p1, string p2, string p3) { var params = new List<string> {p1, p2, p3}; if (params.Any(p => p == null) throw new Exception(...); // rest of constructor logic } }
96. public void SomeMethodParsing( string input) { if (input == “input1”) { someMethod(input); } else if (input == “input2”) { someOtherMethod(input); } // and so on }
So this talk is titled ^ and it will be a summary of some of the ways we’ve made use of the functional style programming constructs introduced in C#3.0 on several projects I’ve worked on over the last year and a half.