Class
In this chapter you will learn:
Create your own class
A class is a template that defines the form of an object. A class has both the data and the code that will operate on that data. Objects are instances of a class. The methods and variables that constitute a class are called members of the class.
The general syntax to declare a class is
[public, // j a va 2 s .c o m
internal,
abstract,
sealed,
static,
unsafe,
partial] class YourClassName [ Generic type parameters, a base class, and interfaces]{
methods,
properties,
indexers,
events,
fields,
constructors,
operator functions,
nested types,
a finalizer
}
Class creation
A class is created by use of the keyword class
.
The general form of a class definition that contains only
instance variables and methods:
class classname {
// declare instance variables
access type var1;/*from java 2 s . co m*/
access type var2;
// ...
access type varN;
// declare methods
access ret-type method1(parameters) {
// body of method
}
access ret-type method2(parameters) {
// body of method
}
// ...
access ret-type methodN(parameters) {
// body of method
}
}
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » Class