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 #005 : Readonly Value Types

Time to review another of Evil Code Series and this time, we are dealing with read-only value types. Review the below code and predict the output.     Strangely enough, the output is {3,2}. Yes, it means the Increment Method return a value of 3 for MyValue, but a follow-up statement to display MyValue explicitly, … Continue reading Evil Code #005 : Readonly Value Types

Evil Code #004 : Conditional Attribute

Continuing with our series of subtle changes that make differences, let's look into Conditional Attributes over Directives. What would be the output of above code under a) Debug Mode b) Release Mode The Debug Mode should be easy and as expected Hello Method01 Hello Method02 One 2 All Done What about release mode ? 3 … Continue reading Evil Code #004 : Conditional Attribute

Evil Code #003 : Casting

Welcome to first post on 'Back to basics'. Yeah, as you guessed right, this series attempt to check minor differences in our understanding of basic concepts. Predict the output of following. Ideally, One would expect the first attempt to fail, but would feel the second would succeed considering we have implemented implicit conversion. But unfortunately, … Continue reading Evil Code #003 : Casting

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