In C#.NET a class is a user defined Data type and is known as Reference Type
A
class can contain following members in C#.NET
1. Data Fields
2. Functions
3. Constructors
4. Destructors
5. Properties
6. Indexers
7. Events
Diagrammatic representation of a class
A class is represented
using rectangle symbol divided into three parts
Data Fields
- It’s used to store the data related to the class
- Except Data Fields no other member of a class can store the data
- To declare any Data Field, we use the following
- Syntax: Access modifier Datatype Data Field Name [=Initializing value];
- Ex: Public int EmpId; string EName; Double salary;
- Access modifier can be any one of
- Default accessibility of a class in internal
Functions
- Any programming language will have methods
- A method is a re-usable piece of a code which can be called again and again and used to perform required tasks
- In any programming language a method can be of two types:
- A procedures is a method which doesn’t return any value to the calling place
- A function is a method which always will return single value to the calling place
- As a function will return some value to the calling place, mentioning return type as void
- Note: C#.Net will support only functions and doesn’t support procedures, whereas VB.Net will support both function and procedures.
Syntax to create a class: Access Modifier class ClassName
Syntax to create an object:
Class Name Object Name=new Class Name
([argumentss list])
Here Class Name
is Constructor name
No comments:
Post a Comment