In C#, can an interface or abstract class be instantiated using the "new" operator ? This probably is one the oldest questions one might have heard as a programmer. And the most obvious answer is a big NO. Well, at this point, I would say it is partially INCORRECT. Why and How The answer "Yes" is perfect … Continue reading EvilCode #14 : Can you instantiate an interface using new operator ?
Category: EvilCode
Evil Code #13 : Tuple Deconstruction Assignment
It is not often that I end up writing two back to back posts on Evil Code series, and that too on the same topic. But like I said in the previous post, Tuples are really an interesting topic (if you are reading Jon Skeet's book, then everything is interesting) In this post, we will explore a … Continue reading Evil Code #13 : Tuple Deconstruction Assignment
Evil Code #12: Tuple Parameter – Overloads and Overrides
Tuples is an interesting subject to go back to due to certain peculiar qualities it possess. In this section, we would address some of them. To begin with, however, we will address how to tuples behave during method overloads - a pattern it share with rest of .Net. Consider the following code. public class Foo … Continue reading Evil Code #12: Tuple Parameter – Overloads and Overrides
Evil Code #011 : Tuples
It has been long since I wrote a post in Evil Code series. So here is a short one, using the Tuples which was introduced in C# 7.X. "introduced in C# 7.x" . You must be wondering why I used that phrase. Tuples was there before 7.x right ? Well, the answer is both yes and no. Tuples … Continue reading Evil Code #011 : Tuples
A second look at char.IsSymbol()
Let us begin by examining a rather simple looking code. What would the output of the above code ? Let's hit F5 and check it. Surprised ?? One should not feel guilty if he is surprised. It is rather surprising one does not look behind to understand what exactly char.IsSymbol does. After all, it is … Continue reading A second look at char.IsSymbol()
Evil Code #010 : Extension Methods
Back with Evil Code Series again. What would be the output of the following. The code attempts to prints 2 set of data, "SampleText" and Null Value. The PrintToString method, prints the output from the inbuild ToString() method, while the second method PrintToDescription, prints the output from an extension method. The extension method, as such, … Continue reading Evil Code #010 : Extension Methods
Evil Code #009 : nameof Operator
The nameof() operator has been so commonly used by the developers that one could not be called guilty if he assumes it was there since C# was born. Despite that, there are days it might still surprise you. What would be your reply if I asked you to predict the output of the following. No … Continue reading Evil Code #009 : nameof Operator
Evil Code #008: Property Instance
It has been long since I blogged on Evil Code series. Time to check one again now. Consider two samples of code. Sample 1 Sample 2 How differently would two of the code samples given below behave ? Well, Sample 1 compiles and Sample 2 doesn't. Why ?? Sample 2, in fact raises following error. … Continue reading Evil Code #008: Property Instance
Evil Code #007: Overloads
Time to do a bit of Evil Code again. Let's look into following set of classes first. The client code looks like following. What could be output of the above ? There might be tendency that the one might be inclined to think about an output that resembles following. But interestingly that is not quite … Continue reading Evil Code #007: Overloads
Evil Code #006 : Build Configurations
This one is courtesy Wouter de Kort, from his famous book. Okay, so what's the evil code here. Consider the following code and predict the output in Debug as well as Release modes. Output of the code under different configurations Isn't that weird that the output has varied in Debug and Release modes ? Well, … Continue reading Evil Code #006 : Build Configurations