C# Intro 1

Saturday, November 2, 2013

Extension methods: static class and method, prefix type parameter to extend with keyword this

Extension method for IEnumerable<string>

System.Linq defines operators for LINQ

  • Standard query operators like Select, OrderBy, Where and many more

One way to invoke a generic extension method that works with strings, ints, doubles ...

Since C# 2.0 possible to use an anonymous delegate instead of invoking the named method

Same intent expressed with a lambda expression, since C# 3.0 and above

Lambdas, funcs and actions

Refactor Filter method use Func instead of delegate

Using Linq operators where and orderbydescending

Linq To Entities

View the generated queries in SQL Server Profiler

Linq Where Operator returns an IQueryable and passes in an Expression of Func<T,bool>

Method and Query syntax

Dynamic, no compile time check, all resolved at runtime

Load non referenced assembly, put it in dynamic object and invoke method

COM interop with dynamic keyword

Expando object arbitrarily add things to the object

Iterating and displaying the members of the expando object

Parse this xml file using the expando object

One possible solution use XDocument, element and a foreach loop

Using an expando extension method to load and parse the xml

Default Success Warning Important Info Inverse
B S W I ? O