Answered Questions

  • C# Program to test efficient coding

    You have several instances of the following class (User). Provide a class with three methods:"AddUser" accepts a User instance as a parameter and add it to a collection."GetUser" accepts a UserID as a parameter and returns the corresponding User instance. It is important that this executes quickly as it will be used often."GetOrderedUserArray" returns an array of User instances ordered by UserID....

    jankajg

    • Sep 25th, 2010

    @asaf122 - your method can be improved a bit by using list. Find even better by lambda expressions) here is howclass UserManager{private List list; internal List List{get { return list; }set { list va...

  • How do I do implement a trace and assert?

    Use a conditional attribute on the method, as shown below: class Debug{[conditional("TRACE")]public void Trace(string s){Console.WriteLine(s);}}class MyClass{public static void Main(){Debug.Trace("hello");}}In this example, the call to Debug.Trace() is made only if the preprocessor symbol TRACE is defined at the call site. You can define preprocessor symbols on the command line by using the /D switch....

    Farohar

    • Jan 22nd, 2009

    Well, you cant add the namespace System.Diagnostics.ConditionalAttribute. Actually you need to add the namespace System.Diagnostics and capitalise "Conditional" like so:using System;using Sy...