Feeds:
Posts
Comments

Posts Tagged ‘c#’

While writing tons of tests I would like to share some of my helper classes here. My first ones are for doing simple performance measurements (not too accurate) and repeating actions.
Code:

using (new Scenario("Sum of all squares from 1 to 100"))
Console.WriteLine("Sum is: {0}", 100.Times(x => x * x).Sum());

using (new Scenario("Print all squares [...]

Read Full Post »

After reading the great article about the code-saving yield keyword “Give way to the yield keyword” by Shay Friedman I thought it could be interesting to know how the yield keyword works behind the scenes.
…it doesn’t really end the method’s execution. yield return pauses the method execution and the next time you call it (for [...]

Read Full Post »

I’ve so often seen people combining paths like this:

string path = basePath + "\\" + filename;

Sometimes they use Path.DirectorySeparatorChar or even check wether basePath or filename already contains. The program then fails with exceptions like "could not find file c:\Program Files\MyProggie\\settings.xml" or even worse files like MyProggiesettings.xml are created, just because the person configuring the [...]

Read Full Post »

For Geeks: Skip explanations, just show the solution!
Well, many of us already utilize this pattern – just without knowing it has a name. I found this name somewhere, and I like it.
On http://aabs.wordpress.com the Intend is defined like this:
Intent: Provide a place to store scope or context related information or functionality that automatically follows the flow [...]

Read Full Post »

Using the using-statement

“Using statement?”, you may ask. “What is so interesting about that? I use it every day importing tons of namespaces!”
Well, i mean the other using statement; that one that results in a nice try..finally in IL, without having to write lots of code.
Well lets say you want to access a file, a database, or whatever [...]

Read Full Post »