Had to do a bit of head-scratching on this one. New projects created in Visual Studio 2008 did show the “Add Service Reference” when right-clicking on a project in Solution Explorer while some existing ones didn’t. Using “Add Web Reference” instead of “Add Service Reference” has its own set of issues in that WCF services… [Read more…]
I was describing how a simple yet extensible report-generator could be implemented quickly to somebody. I’m posting it here as some of you might find it useful (and I can refer to this link in future conversations ). The concept: …is really simple. The idea is to look for a placeholder like @Fruit and replace… [Read more…]
What’ll be the output of the following piece of code (asked here)? One might expect… True True But what you’d actually get is… False False …because of boxing. a.Add(1) boxes the integer 1 into an object and stores it in a, while b.Add(1) boxes the integer 1 into a separate object and stores it in… [Read more…]
Try-Catch-Finally A try-catch-finally is converted into IL by the C# compiler as a try-catch inside the try block of another try-finally. This allows for finally block to execute even when exceptions are raised in the catch block. Use ildasm and check it out yourself! throw football; Though you cannot throw an arbitrary managed object as… [Read more…]
In an internal meeting of a bunch of developers at my current company, someone made the assertion that the Switch statement in C# (or Select Case in VB.NET) is just a compiler short-cut for writing a chain of If-Then-Else statements. What do you think? Is that statement – true or false? Take the following C#… [Read more…]
Problem: Consider the following generic function written in VB.NET: What message do you expect to be shown by the following bit of code? Would the “Foo” method even compile? It doesn’t make sense to assign a Nothing (VB.NET equivalent of C#’s null) to a value-type, right? Solution: Well, the code compiles just fine. When synthesizing… [Read more…]
Problem: Do warning bells go off in your head when you see code like the following? Are there any problems you need to be aware of when declaring events inside structures? Solution: Well, code like the following wouldn’t work, even though it seems to be perfectly reasonable. foo_SomeEvent will actually never be called. Why? Remember… [Read more…]
Problem: I had used .NET Mass Downloader tool to download .NET 2.0 Framework sourcecode some time ago. While reading Timer.cs (System.Windows.Forms.Timer) and a couple of other classes I noticed something interesting. Does the following piece of code look odd to you? Notice the empty “try” block and all processing being done in the “finally” block.… [Read more…]
Problem: .NET 2.0 introduced the GZipStream class to allow programmatic compression and decompression of files. However that class doesn’t provide an easy way for us to determine if a file is actually a compressed file. Decompressing the entire file just to determine if a file is actually compressed is wasteful. Solution: Most files have a… [Read more…]
If you’re reading this article, you’re most probably familiar with the InvokeRequired property on Windows.Forms.Control class which we have to use whenever setting a property on a Windows Forms control from a thread other than the one it was created on. Here is what the MSDN page about InvokeRequired says: Controls in Windows Forms are… [Read more…]
July 22, 2008
22