Monday, August 1, 2011

What are Classes and structures

Structures

A structure in C# is simply a composite data type [you are well aware from composite data type, refer to data types for more details], which consists number of members of other types. The structure define simply by using the struct keyword.

eg. struct enroll
{
public string name, fname, mname;
public string char sex;
Public int age;
public string address;
}

Classes

It is cleared from above study that Classes are reference type. A class is a collection of its data members. Data members are those members of class which contains the data of class like fields, constants and events etc. Class is declared simply just followed by class keyword with optional modifiers; by default C# classes are public.

eg. class myClass
{
public int xyz;
public string name;
public const int y=22;
}

No comments:

Post a Comment