Wednesday, 27 July 2016

C Sharp Static Class Tutorial

C# Static Class Tutorial

class testmath
    {
        public static int sum(int a, int b)
        {
            return a + b;
        }
        public static Boolean prime(int a)
        {
            int b;
            for (b = 2; b < a; b++)
            {
                if (a % b == 0)
                    break;

C Sharp Delegate

C# Delegate 

A delegate is a simple class that is used to point to methods with a specific signature, becoming essentially a type-safe function pointer.
If you have a C++ background then  thinking of them as function pointers is helpful
A delegate can be seen as a placeholder for a/some method(s).
By defining a delegate, you are saying to the user of your class 
"Please feel free to put any method that match this signature here and it will be called each time my delegate is called".
class Program
    {
        delegate int mathop(int n, int m);//funtion pointer
        public  static int sum(int a, int b)
        {
            return a + b;
        }
        public  static int multi(int a, int b)
        {
            return a * b;
        }

C Sharp Class Basics Tutorial

C# Class Basics Tutorial

class student
    {
        int roll;
        string name;
        string city;
        public void setdata(int r, string n, string c)
        {
            roll = r;
            name = n;
            city = c;

C Sharp Variable Scope

C# Variable Scope

class Program
    {
        static void Main(string[] args)
        {
            int n = 10;
            {
                int m = 20;
                {
                    int p = 30;
                    Console.WriteLine("N={0}\nM={1}\nP={2}", n, m, p);
                }