What are Classes and structures
A very basic and common questions asked many time to freshers, novoice or intermediate level interviews. I got many emails for the same questions, hereunder I try to answer in a simpler way.
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;
}
Look into more details at : http://gauravarora.indiamentor.com/Chapters/csharplanguageii.htm
Popularity: 7% [?]
Related interview questions
- Can I inherit two difference classes to partial classes?
- Is it possible to create constructor for an Abstract class?
- How can I create a Singleton class by using public constructor?
- Can we store filtered DataView in ViewState?
- Can we maintain state in webservices?











Leave your response!
You must be logged in to post a comment.