Like classes, structures contain data members which are defined with in the declaration of the structure.
However structures differ from classes and the differences are :
- structures are value types and get stored in a stack memory where as classes are reference types and stored in heap memory.
- structures do not support inheritance where as classes support inheritance.
- structures do not have default constructors.
For example if you want to maintain the employee details, such as employee id, employee name, joining date, designation, in a single variable, you can declare a structure.
The following code shows the syntax of a structure data type:
public struct employee_details
{
public string emp_id;
public string emp_name;
public string join_date;
public string designation;
};
No comments:
Post a Comment