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

Advertisement

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

Evil Code 0002 Optional Parameter Vs Method Overloading

Again one of those things which looks so simple, but could drive one mad during debugging. Much before Optional Parameters came in, C# developers used to depend on Method Overloading for mimicking Optional Parameters. Consider a scenario where both exists, what would be the output ? The output would be : The reason behind this … Continue reading Evil Code 0002 Optional Parameter Vs Method Overloading

Evil Code 0001 : Lambda and Ref/out

What would be output of following ?         static void Main(string [] args)         {             List< int> numlist = new List< int>() {1,2, 3, 4, 5, 6, 7 };             CalculateAndPrint( ref numlist);         }           public static void CalculateAndPrint( ref List< int> Num)         {             var n = Num.Where(d => d > Num[2]);               foreach ( var item in n)             {                 Console.WriteLine(item);             }         } The most obvious answer is … Continue reading Evil Code 0001 : Lambda and Ref/out