Tuesday, 10 July 2012

Seventh Class (Parameter)

Seventh class material (function with parameter, Instance Variable)

Function with parameter

public static void Main(string [] args)

This is called function with parameter, Here (string [] args) is called parameter.

'string' is Data type ' [] ' is array and 'args' is name of variable or name of array.

Example : 1


using System;
class arr
{
public void abc(int a, int b)
{
int c=a+b;
Console.WriteLine("Sum is : "+c);
}
public static void Main()
{
arr d=new arr();
d.abc(3, 5);
}
}

Instance Variable and instance function/method/behaviour



using System;
class Instance
{
int a, b, c;
public static void Main()
{
Instance i=new Instance();
i.a=2;   //we can declare here also like this    i.a=2;i.b=3;
i.b=3;
i.c=i.a+i.b;
Console.WriteLine("Result is : "+i.c);
}
}

Instance Function


using System;
class Instance
{
public void Roy()
{
      Console.WriteLine("this is Believe Techno");
}
public static void Main()
{
Instance i=new Instance();
i.Roy(); //it called instance function

}
}


Access Variable and Function without instance.


using System;
class roy
{
public static int a,b,c;
public static void believe()
{
Console.WriteLine("Hi static function");
}
public static void Main()
{


                believe();   //we dint need here to make object or instance..
a=3;b=4;
c=a+b;
Console.WriteLine("Result is :"+c);
}
}

Non static variable cannot access in non static function without instance but static variable can directly access to the static function.

2 comments:

  1. Short, Described & effective Content, Good Start For Beginners...

    ReplyDelete
  2. Thanks For Your response....

    ReplyDelete