You are on page 1of 4

Awesome C sharp : About Functions and keywords

by santosh Namastey friends (welcome friends).... how are u ? must be good thanks for visit again. let's go further in programming and start learning about c sharp functions keywords, variable and so on...... What are functions and keywords ? usually what happens we start out coding in the Main() function which is starting point of programming code while doing programming it was felt that a certain piece of code is required again n again. and i felt that i m writing same line, which increases the length of my code and my efforts so i required i block of code which can be used as many times i require them. that block or code know as function. There are two types of functions (1: System Defined) (2:User Defined) Let us under them one by one.... #System define first :Awesome c sharp is wonderful and easy language to know because awesome C sharp contains several system defined functions some of them are common to u u have used them in my previous post remember Console.WriteLine(); Console.ReadLine(); Console.Read() an so many if u forget that please visit again http://awesomecsharp.blogspot.in/2013/05/console-class-in-more-detail-bysantosh.html that will help u # User defined function:User defined functions are user defined / created by user in the program as his/ her requirement these are reusable component of programmer now see how to create them while coding have a look in this code

using System; class Car { public static void Accept() {

Console.WriteLine("Accept invoked"); } public void Display() { Console.WriteLine("This is Display function"); } public static void Main() { Accept(); Car C = new Car(); C.Display(); Console.ReadKey(); } }

here in this example Console.WriteLine(); and Console.ReadKey(); are system defined functions and Accpet() and Display(); is use defined functions u can do any type of coding within these user defined function.
now in this awesome c sharp code we have created two type of function static and non static ___________________________________________________________ static function

public static void Accept() { Console.WriteLine("Accept invoked"); } ___________________________________________________________

non static function public void Display() { Console.WriteLine("This is Display function"); } ______________________________________________________ both are two different functions Accept() which is static and Display() which is normal function, but the major difference between these function is that static function Accept() can be invoked directly without initialize object of the class where as for calling Display() function we will need and object of class which need to be initialize before calling it......... see the Main() function _____________________________________________________________________ ___ public static void Main() { Accept(); //................................... need no class Car object. Car C = new Car(); memory for c object. C.Display(); object of Car class // Car class object is C, new keyword will help to initialize the

//....................... finally calling Display function through C

Console.ReadKey(); //............................... holding command prompt } } Note: u can also call Display function via this code............................ new Car().Display();

_____________________________________________________________________ _______

For more information please visit


http://awesomecsharp.blogspot.in/2013/06/awesome-c-sharp-about-functions-and.html

__________________________________________________________________ all right reserved it 2013 awesome c sharp brought to u by vardana solutions _________________________________________________________________

You might also like