consider the following code example,which desines a class:
plublic class hello
{
public static void main(string[] args)
{
system.concole.writeline("hello, world! \n");
}
}
the precending class declaration provides a method main() that will display the message "hello, world!" on your screen. The parts of the preceding code need the be examined.
The Main() Function
The first line of code that a C# compiler looks for in the source fle compiles is the mail() function is the entry point of the application.
The main() funtion is ideally used to create objects and invoke member functions.
The class keyword
The class keyword is used to declare a class. keywords are reserved words that have a special meaning. Here, the class keyword defines the class Hello. the braces, knon as delimiters, are used to indicate the start and end of class body.
Example:
Class Hello
{
....
}
The class Name
The class keyword is followed by the name of the class. in the preceding example, hello is the name of the class defined by using the class keyword. When you create classes, you must consider the following naming convention and rules.
Class Naming Conventions in C#
class names should follow certain naming conventions or guidelines. A class name:
* should be meaningful(strongly recommended).
* should ideally be a noun.
* can use ethire the pascal case or camel case. in pascal case the first letter is capitalized, such as myclass.
The Escape Characters
To display special characters such as the New line character or the backspace character,
you need to use escape characters.
The following table list the escape characters used in C#.
Escape sequence character name
\' single quotation mark
\>> double quotation mark
\\ Backslash
\0 NULL
\a Alert
\b Backspace
\f Form feed
\n New line
\r Carriage return
\t horizontal tab
\v vertical tab
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment