C# Intro 3

Sunday, November 3, 2013

While loop could generate an infinite loop but yield return yields a number to the calling code and exits the function


Specifiy a maximum number for the random generator of 100 so the numbers don't run off the console window


Timewatcher class, pass in an action into metric method and return time to execute this action


Create an instance of timewatcher, invoke metric method and embed the existing code in main method in a lambda expression, passing in the result in variable and then print it out to the console


Extension method for every function that takes no parameters and returns a value of type t, if it fails retries up to 5 times


Invoking the method withretries


How to retry a function that itself needs a parameter value? Withretries only works with functions that take zero parameters


Partial function application transforms a function that takes n parameters to a function that takes n-1 parameters


Application of Partial extension method to solve the problem


Another technique to adapt functional API's to match each other is currying, transform a function that takes n parameters to function that invoked and get back as a result a function that takes n-1 parameters


Invoking the curry method


Calculate execution time to get prime numbers between 400000 and 500000


It takes about 18 seconds


GetLargePrimesInParallel uses the AsParallel() Linq operator

TPL AsParallel executes in about 10 seconds


Parallel class provides more fine grained control


Another API to create Tasks


Chain tasks together with continuewith


Crafting Code - make code readable and follow standards


Naming: classes should be pascal cased whereas parameters should be camel cased


Methods do something and should have a verb in them, Properties are state and should have a noun in them

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