"using", the safe keyword

It is interesting how Microsoft helps you ease the amount of work. What to do with objects when an exception is thrown? Well... In Java you have a try-catch-finally. The same thing you have in C#. Microsoft however took it a step further. Sometimes we don't care what the exception is we just want to...

Getting rid of nullable type Linq

This was quite annoying. I was trying to convert the output from the database into an array. Everything was great null it started throwing an error that the conversion is a nullable type int?[] In order to get rid of it there was a nice and simple trick:

Getting Midnight Time for DateTime

Presumably easy thing to do. How to get only date for DateTime? DateTime.Now! Well... Not Quite, because it returns the time as well. Fortunately, we don't have to design any algorithms to do do it for us. It turns out that DateTime struct also contains Today attribute which returns current day without returning the current...

foreach image in a resource file

Today, I was working with artificial intelligence. In order to perform the training I had to load images. Well, surely I wasn't going to go through every instance of the image and learn like this:

Instead, I used ResourceSet like so:

Much neeter

Useful Linear Trendline Class in C#

I've searched and searched trying to find a simple class to calculate a slope and intercept from a set of points. Here is the outcome, but I probably modify it to use LINQ rather then loops

Displaying an image from binary source (like a database)

Today I had to display an image from the database on the website. Here is the code:

This expression should be of type 'unit', but has type 'int'...

Today, I started learning F# to use Infer.NET. It's a shame MS doesn't support it any more. The second line and already got an error. Not a good sign...

This however is useless. Unlike Haskell, F# doesn't print the result unless explicitly stated. So we need to be a bit more clever than...

Splitting Web.config into multiple files

Reading large XML isn't fun and that's kind of what started happening to my web.config file: tracing, entity framework, database connection strings, service endpoints definition etc, etc, etc... Thankfully there is a way of splitting the web.config into multiple files so that it is easier to read and modify. Create new config file: preferably with...

Using Tracing with WCF Service Log

Using tracing can be very beneficial especially when the application has already been deployed and we need to figure out why it doesn't work. Useless errors of type: 500 don't give any meaningful results, so I decided to use System.Diagnostics to help me track down the errors. Logging There are two important (and very simplifed...