Tuesday, May 8, 2012

Extensions Methods in C#

C# extensions can be used to extended the  functionality of already written class. (Yes it is true that we can use it for our classes as well. But then we can add the method directly rather than having it as extension method)

Following example shows a extension method which I used for extend the functionality of the windows.form class.

public static class Extensions
{
public enum SpliterModes
{
PanelOne,PanelTwo
}

public static void Show(this Form frm, String name)
{
frm.TopLevel = false;
frm.Visible = true;
frm.FormBorderStyle = FormBorderStyle.FixedSingle;
frm.MaximizeBox = false;
frm.Text = name;
}
}
image
Post a Comment