finally and Return Values !!!

Let us read some code:- [code lang=csharp] int SomeMethod() { int num = 1; try { num = 5; return num; } finally { num += 5; } } [/code] What is the return value of SomeMethod? Some anonymous guy asked that question in the code project forum, and it has been answered. I am writing about…

Type Safe Logger

Sanjeev and I have published an article – Type Safe Logger For C++ – at CodeProject. Every bit of work is tiresome or little ugly in C++. So is logging – writing application diagnostics to console, file etc. The printf style of outputting diagnostics is primitive and not type safe.…

Simple Array Class For C++

This is a simple array like class for C++, which can be used as a safe wrapper for accessing a block of memory pointed by a bare pointer. Disclaimer: It is not aimed to replace the STL containers. #pragma once template class Array { private: T* _tPtr; private: size_t _length;…

CComPtr Misconception !!!

This is about a killer bug identified by our chief software engineer in our software. What was devised for ease of use and write smart code ended up in this killer defect due to improper perception. Ok, let us go! CComPtr is a template class in ATL designed to wrap…

Settling Casting Restrictions !!!

Remember the Casting Restrictions we discussed a while back, let us settle that now. So we have some code like this: int i = 100;object obj = i;long l = (long)obj; And an invalid cast exception while casting ‘obj’ to long. It is obvious that we are not…

The WD Anti-Propaganda Campaign !!!

Thanks to the internet. If nobody else bothers or understands what loss of data means, you can shout it aloud here. I lost 500GB of data – every moment of my personal and professional life captured in bits and bytes. It is a Western Digital Premium Edition external hard disk…

Casting Restrictions ???

We all know that the runtime can detect the actual type of a System.Object instance. The primitive data types provided by the runtime are compatible with one another for casting (assuming that we do not truncate the values). So if I have an int, it can be cast to…