Tag: C#

TechQuiz Question 8: On precedence and operators

What is the output of the following program? class Program {     static void Main()     {         int result = x() + y() *         Console.WriteLine(result     }     static int x()     {         Console.WriteLine(“x”);         return 3;     }     static int y()     {         Console.WriteLine(“y”);         return 2;     }     static int z()    ...

Tech Quiz: Some micro optimization

Optimize the following code: doubletotalCount = 0; for (int index = 0; index < numberOfRuns; index++) {     string[] values = GetData(index);     totalCount += values.Count(); } Answer A simple optimization is to replace Count() with Length. Count() is an extension method that looks something like this: public static int Count<TSource>(this IEnumerable<TSource> source){    if (source == null)    { ...