How overriding Object.ToString() helps

System.Object provides a ToString() method which gives a human readable string about the object. Many people haven’t realized how useful is this tiny method.

Consider the following code:

namespace PersonDetails
{
    class Person
    {
        public Person(string firstName, string lastName, int age)
        {
            this.FirstName = firstName;
            this.LastName = lastName;
            this.Age = age;
        }

        public string FirstName { get; set; }
        public string LastName { get; set; }
        public int Age { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Person chuckNorris = new Person("Chuck", "Norris", 20);
            Console.WriteLine(chuckNorris.ToString()); // Prints PersonDetails.Person
        }
    }
}

The information printed is not at all helpful. Let us override ToString() and see the difference. Continue reading

Advertisements

Understanding equality and object comparison in .NET framework

.NET framework provides several methods to do comparison and equality check for objects. It can be pretty confusing at the beginning by looking at the documentations for each interfaces that framework offers. In this post, I will try explain the possibilities with examples.

Basically, there are two kinds of equality in .NET. Reference Equality and Value Equality. Default is reference equality. To understand reference equality, consider the following class: Continue reading

Getting smart-completion for wxWidgets using CEDET

This post shows how CEDET can be configured to show code-completion for classes in wxWidgets library. Since wxWidgets uses preprocessor macros heavily, configuring smart-completion is bit tricky. I haven’t got successful completion on my first attempt and got everything worked nicely after having few discussions on the CEDET mailing list. Thanks to all who helped.

This post assumes that you have a CVS version of CEDET installed and configured correctly. Continue reading