Browse by Tags
All Tags »
software C# language (
RSS)
I'll bet a hundred bucks that any entry level C++ interview or exam will somehow drift into questions about the pre and post increment operators. It's almost become a canonical, rite of passage sort of thing. Now using the operators is one thing...
There are times when you feel really proud of yourselves; on top of the world, with no one in sight. And then there are times when you can't believe you did what you just did. Here's one of the latter :- My task was to show a progress bar in our...
There have been a lot of blog posts about why calling Thread.Abort from one thread to abort another is a bad idea. If you're still wondering if it actually is that bad, you'll be convinced by the end of this blog post :). The other day, I was...
Implementing IEnumerable<T> can turn out to be tricky in certain cases. Consider the following code snippet namespace Test { class Program { static void Main( string [] args) { Consume( new List < string >() { "a" , "b"...
This is one topic that keeps popping up every now and then. A lot of people seem to be curious about the performance implications of using one versus the other, and not unexpectedly, a lot of different answers come up. To settle it once for all, here's...
Tee is a cool function that "clones" enumerators whatever their current state is - it basically allows you to branch off an enumerator into as many enumerators as you want, all independent of each other. You can do something like List<int>...
Every now and then, you hit some problem that a programming language helps solve very cleanly. Here's the problem. You are writing a series of functions that return a bool depending on some condition (predicates). Something like bool Foo(State t);...
There is a description of the bug here . The following piece of code demonstrates the bug. class Program { interface I { int X { get; set; } } struct S : I { public int X { get; set; } } static void Main(string[] args) { Func<S>(); } static void...
We saw in Part 1 that C# doesn't allow an instance field initializer to refer another field in the class. Before trying to figure out why, let's first see if this is a restriction imposed by C#, rather than by the CLR. Some disassembling and reassembling...
What do you think of the following piece of code? class Program { int x = 1; int y = x + 1; } Looks simple, except that it doesn't compile (error CS0236: A field initializer cannot reference the non-static field, method, or property 'Program.x'...
Local variable type inferencing is a new feature in C# 3.5 - a very "handy" one, in that it saves a lot of typing. Basically, it lets you do var dict = new Dictionary<string, List<int, Dictionary<int, string>>>(); instead of...
Polymorphism, which attempts to hide differences in implementation, and generics, which attemtps to highlight them by providing exact information about types, don't seem to mix very well. Consider the following fairly common pattern. class Base {...
If there was ever a poll conducted for the most favorite C# operator, I'd guess the conditional operator ?:, also known as the ternary operator, will win hands down. I find it to be one of those tools that make things shorter and clearer at the same...