Cl@sses in C#

In general we know that a class consists of Member data and Member functions. so similarly in C# a class definition contains Member data and function . Now let us consider an example of a class in C#

public class Hello
{
public static void main(string [] args)
{
system.console.WriteLine("Hello, fnds");
}
}

Now we shall learn about each and every step in detail

1. In any programming language the execution starts from main function and this is said to be the entry point of the application.

2. Main function is used to create objects and invoke member functions.

A class keyword is used in order to create a class . While designing a class we have to remember the following class naming conventions.

  • should be meaningful.
  • should identically be a noun.
  • we can use either pascal case or camel case, where in pascal case the first letter is capitalized and rest are small (ex: Hello) cmg to camel case the first letter is in lower case and first letter of each subsequent word must be in caps (ex: myClass).
    Rules for naming a class is
  • They must be begin with a letter and not with digits or special symbols.
  • a class name should not contain any special characters (other than '_').
  • We must not declare a class with any keyword .
    • Now coming to System.Console.WriteLine()
      Here Console is a class that belongs to System namespace . A namespace is a collection of classes . The system namespace contains the method WriteLine(), which displays the enclosed text on the screen. The console class has other methods, which are used for various input/output operations. The character (.) is used to access the function, WriteLine(), which is coded in the Console class of the System namespace.
      here from the above example the statement Console.WriteLine("Hello, fnds"); gives the output as Hello, fnds. It is similar to printf (in C), cout( in C++) .
    • We can also use escape sequences in these output statements.
    • "String [] arg" declared in main function means that is a predefined class name which takes only one argument . It allows a programmer to pass inputs at command line level. In java we pass this as 'main(String arg[])'.

0 Comments:

Post a Comment



Newer Post Older Post Home