C#

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Saturday, 9 November 2013

Class concepts you must know


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WOW
{
    class anurag
    {
        public int x, y;
        public anurag()
        {
            Console.WriteLine("i am anurag");
        }
        public anurag(int a, int b)
        {
            Console.WriteLine("custom constructor");
            x = a;
            y = b;
        }

    }

   
   
   
   
    class anu1
    {
        public static int Main(string[] args)
        {
            anurag a = new anurag();
            anurag b = new anurag(40, 50);
            Console.WriteLine("values {0}", b.x + b.y);
            Console.ReadLine();
            return 22;
        }

    }
}


//This program runs......Actually the public int x,y should be there in first class....if its there in class anu1...it will give you a error.....//

x doesnot exist in the current context.....
y doesnot exist in the current context......bla bla

///


If the code is like this::

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WOW
{
    class anurag
    {
     
        public anurag()
        {
            Console.WriteLine("i am anurag");
        }
        public anurag(int a, int b)
        {
            Console.WriteLine("custom constructor");
            x = a;
            y = b;
        }

    }

 
     public int x, y;
 
   
    class anu1
    {
     
        public static int Main(string[] args)
        {
            anurag a = new anurag();
            anurag b = new anurag(40, 50);
            Console.WriteLine("values {0}", b.x + b.y);
            Console.ReadLine();
            return 22;
        }

    }
}


// you will get error as like this...

Error:Expected class, delegate, enum, interface, or struct.......



Here everything works fine as everything remains in a class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WOW
{
    class anurag
    {

        public anurag()
        {
            Console.WriteLine("i am anurag");
        }
        public anurag(int a, int b)
        {
            Console.WriteLine("custom constructor");
            x = a;
            y = b;
        }

        public int x, y;

        public static int Main(string[] args)
        {
            anurag a = new anurag();
            anurag b = new anurag(40, 50);
            Console.WriteLine("values {0}", b.x + b.y);
            Console.ReadLine();
            return 22;
        }
    }
}
...

so no problem...

No comments:

Post a Comment