Different Types of Constructors in C#

A constructor is a method in the class which gets executed when its object is created. A constructor is usually used to initialize data members of the class. There are four different types of constructors: Default Constructor When you do not declare any constructor, the class will call its default constructor. The default constructor is a parameter …

Continue reading Different Types of Constructors in C#

How can you find a control in an ASP.NET page from code behind

Lets suppose we have an ASP.NET page and we have the following control in it: <asp:Label runat="server" ID="label1"></asp:Label> To find the control in the page from code behind, you have to do the following: Label lbl = this.FindControl("label1") as Label; This will work in any normal ASP.NET page, but will not work if you using a Master …

Continue reading How can you find a control in an ASP.NET page from code behind


The need to create class that can work with any type of data is increasing. Generics allow you to define type-safe data structures, without committing to actual data types. By using Generics, you get to reuse data processing algorithms without duplicating type-specific code. Generics, when compared to inheritance, can increase type safety and reduce casting and boxing. Generic …

Continue reading Generics

What is the difference between arrays and collection?

Array: You need to specify the size of an array at the time of its declaration. It cannot be resized dynamically. The members of an array should be of the same data type. Collection: The size of a collection can be adjusted dynamically, as per the user's requirement. It does not have fixed size. Collection …

Continue reading What is the difference between arrays and collection?

URL Routing in ASP.NET 4

Normally when you access a web page, you use a URL that is the physical path of the page. URL routing is a way to provide your own URL instead of the physical path. ASP.NET 4.0 provides us with a simple and strong way to handle URL routing. ASP.NET 4.0 router enables to define any …

Continue reading URL Routing in ASP.NET 4

How to load string to XMLDocument()

The following example shows you how to load a string to a XMLDocument() object: 1. Load from a physical file on a drive: XmlDocument _Document = new XmlDocument(); _Document.LoadXml(File Physical Path); 2. Load from a URL: WebClient wc = new WebClient(); string xmlStr = wc.DownloadString(url); XmlDocument _Document = new XmlDocument(); _Document.LoadXml(xmlStr);

List all databases on a SQL server and bind to a dropdown list

SqlConnection con = new SqlConnection("server=server;uid=username;pwd=password");                     con.Open();                      SqlCommand com = new SqlCommand();                      com.Connection = con;                      com.CommandType = CommandType.StoredProcedure;                      com.CommandText = "sp_databases";                      SqlDataReader reader = com.ExecuteReader();                      while (reader.Read())                                 ddlDatabases.Items.Add(reader.GetString(0));                  con.Close(); Note that this is not the only method to to do this.

Introduction to Inheritance

Inheritance is the principle that you can apply your knowledge of a general category to more specific objects. The classes you create in object-oriented programming languages can inherit data and methods from existing classes. When you create a class by making it inherit from another class, you are provided with data fi elds and methods …

Continue reading Introduction to Inheritance