Saturday, April 7, 2012

Ranking of Programming Languages

The TIOBE programming community index shows the popularity of programming languages. This index may be used to check our programming skills are up to date or not. It does not matter about technology rather than logic. But language shows its power. So here you can see updated index, growth of language and their history. See here


Sunday, January 22, 2012

Extension Method


An extension method is a language feature of c# from 3.0. A programmer always faces problem when he/she needs to add a new method in existing class. If it is required then what we can do are

1. Inherit the existing class in new class and implement the method
2. Implement the required functionality in other class with static modifier
3. Use aggregation

But all have its disadvantage like if we go for first option and existing class is sealed (restrict inheritance). Second option is solved problem of first one but here we have to use someone else reference (other class).
But this new feature of extension method solves these problem (some other also). This approach requires a static class with a static method.

Example

class Car 
{
}
static class ExtensionMethods
{
    public static void GetCar(this Car c)   
    {                               
        Console.WriteLine("Call extension method");
    }                               
}
The signature of extension method there is a "this" before the first argument. It shows that this is an extension method. So we can call our extension method
Car c = new Car();
c.GetCar();
Here we are calling GetCar method by car reference with.

Tuesday, December 6, 2011

Event

Event:
An event in C# is a way for a class to provide notifications to clients of that class when some interesting thing happens to an object.

Example:

    class Program
    {
        static void Main(string[] args)
        {
            var dialogForm = new DialogForm();
            dialogForm.OnDialogClosed += new DialogForm.DialogClosed(dialogForm_OnDialogClosed);

            Console.WriteLine("Dialog is shown.");
            dialogForm.ShowDialog();
            
            Console.WriteLine("Dialog data is saved.");
            dialogForm.SaveData();

            Console.ReadLine();
        }

        static void dialogForm_OnDialogClosed(object sender)
        {
            //Take action after closed dialog
            Console.WriteLine("Dialog is closed.");
        }
    }

    class DialogForm
    {
        public delegate void DialogClosed(object sender);
        public event DialogClosed OnDialogClosed;
        
        public void ShowDialog()
        {
            
        }
        public void SaveData()
        {
            if (OnDialogClosed != null)
                OnDialogClosed(this);
        }
    }

Explanation:
Here DialogClosed is a delegate and OnDialogClosed is an event.
Scenario : We want to show a dialog form where user can enter some data and after that he can save data. When data has been saved then a closed event fire from Dialog to notify caller that I have closed.

Sunday, December 4, 2011

Anonymous Method

Anonymous Method :
We have seen a delegate now it's time to know about Anonymous Method. So we can create a delegate instance without using method name.

Example :
    class Program
    {
        public delegate int OperationDelegate(int a, int b);
        static void Main(string[] args)
        {
            OperationDelegate addOperation = delegate(int a, int b)
            {
                return a + b;
            };
            Console.WriteLine(addOperation(10, 20));
            Console.Read();
        }
    }

Explanation:
We have put a method inside a block. which is anonymous method.

Wednesday, October 5, 2011

World’s first chromebook

World’s first chromebook
Samsung Chromebook Series 5: What You Need to Know

Google and Samsung have unveiled the “world’s first chromebook,” the Chromebook Series 5. We had the opportunity to take it for a test drive.