Executable C# Class:
Every C# class, which needs to be run as an executable needs to have the following method:
public static void Main()
{
}
or
public static void Main(String[] args)
{
}
When you run the compiled exe, the code in the
Since we wanted to create an exe, our code also contains this code, which is
called when the exe is executed.
The next line we need to understand is :
Console.WriteLine("Hello World! How are you");
The WriteLine method in the System.Console class, lets you specify a string, which
is printed on the system console.
The Console class is part of the System package in the Core .NET classes.
Classes:
The class is a foundation of an Object orieneted programming paradigm. You can use a class to encapsulate the complexity of physical implmentation from other programming units. Anybody can get the benefits of this implementation as long as they know the constructors, the destructors and the methods.
The Constructor:
A constructor is a method with the same name as the class. A blank constructor is automatically called when the object of the class is created. One of the key difference between a normal method and a constructor is that , the constructor does not return any value.
Methods :
A method is a wrapper for a sectional piece of code in a class, which does implments a part of the functionality of the class itself. For example, if you have a class called Calculator, there may be methods like addNumber(), substractNumber()
Method Parameter:
Methods can be defined with parameters, every parameter is defined with its datatype. For example addNumber (int firstNumber, int secondNumber)
Method return values:
Methods are required to define a return data type, or if it is intended to not return type, then the method should be defined as returning void. For example : public void resetNumbers()
No comments:
Post a Comment