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

Getting rendered HTML of a server control

This post shows a generic method that can return the HTML string generated by ASP.NET server control after the rendering.

string GetRenderedOutput<T>(T control) where T : Control
{
    StringBuilder builder = new StringBuilder();
    using (StringWriter sWriter = new StringWriter(builder))
    using (Html32TextWriter writer = new Html32TextWriter(sWriter))
    {
        control.RenderControl(writer);
    }
    return builder.ToString();
}

How small code optimizations can improve the performance and storage requirements

While reading an algorithms book, I learned that minor optimizations and choosing right algorithm can improve the code performance drastically. In this post we will see how this is happening.

Consider the following trivial code to calculate a Fibonacci value of a number using recursion.

int fibonacci(int num)
{
if (num < = 1) return num; else return fibonacci(num - 1) + fibonacci(num - 2); } [/sourcecode] Here is how this code executes for fibonacci(5). Continue reading

Disabling a custom control from Visual Studio’s toolbox

When a custom control is created, Visual Studio will show it in the toolbox for dragging and dropping. This can be annoying when you create a composite control which is a combination of several other custom controls where VS will display all custom controls in the toolbox. System.ComponentModel.ToolBoxItemAttribute can be used with the controls that you want to hide from toolbox. Apply this attribute to all the controls that you want to hide from toolbox.

Sample code

[System.ComponentModel.ToolboxItem(false)]
public class MyCustomControl : Label
{
}

MyCustomControl will not be displayed on the toolbox.

Circular linked list – An implementation using C#

In this post, I will explain about creating a circular doubly linked list using C#. .NET framework provides a doubly linked list implementation in System.Collections.Generic.LinkedList<T> class . But this class is not providing the behavior of a circular linked list and it is very tough to extend for supporting circular linked list requirements.

In a normal doubly linked list, each node will have a link to its previous and next nodes. In a circular doubly linked list, tail node’s next node will be head and head node’s previous node will be tail. Here is an image taken from wikipedia which visualizes circular linked list.

Circular linked list
Continue reading

What Great .NET Developers Ought To Know (More .NET Interview Questions and Answers) – Part1

In this series of posts, I will try to answer the questions posted by Scott Hanselman here. This part we will be seeing the first set of questions he has given under Everyone who writes code heading.

Q) Describe the difference between a Thread and a Process?

A Thread is a small unit of code in execution. A process is an instance of program which will have multiple threads running. A process can host multiple threads. Thread will always belong to a process. Communication between multiple processes are difficult but communication between threads is easy.

Continue reading

What is the difference between typeof(Foo) and myFoo.GetType()?

This question is taken from Scott Hanselman‘s What a .NET developer should know post. To understand the difference, let us write a simple program.

class Foo
{
    /* .... */
}

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("typeof(Foo) = " + typeof(Foo).Name);
        Foo f = new Foo();
        Console.WriteLine("f.GetType() = " + f.GetType().Name);
    }
}

Here is the output.

command-prompt

Let us add a subclass for Foo and try again.

class Foo
{
}

class SubFoo : Foo
{
}

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("typeof(Foo) = " + typeof(Foo).Name);
        Foo f = new SubFoo();
        Console.WriteLine("f.GetType() = " + f.GetType().Name);
    }
}

command-prompt1

In general, f.GetType() returns runtime type of the instance. typeof(Foo) gives the compile time type of Foo.