C#

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Sunday, 10 November 2013

property basics


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace definingclass
{
    //utility class
    class Program
    {
        public short x = 0;
        public short y = 0;
        public int i = 10;
        string str;
        public bool hasprintcode;
        public readonly string sprinter;


        public Program()
            : this("default constructor")
        {
            hasprintcode = false;
        }

        public Program(string s)
        {

            str = s;
            if (!this.hasprintcode)
            {
                this.hasprintcode = true;
            }
        }


        public short X
        {
            get
            {
                return x;
            }
            set
            {
           
            if ((value>=0) && (value <1000))
                {
               
                x=value;
                }
            }
           
        }

        public short Y
        {

            get
            {
                return y;
            }
            set
            {

                if ((value >= 0) && (value < 1000))
                {

                    y = value;
                }
            }
       
       
        }

        public Program(string spid, int i)
        {
            sprinter = spid;
            this.i = i;

        }
        //a custom constructor
        public Program(int i)
        {
            str = i.ToString();

        }

        //instance method
        public void printstring()
        {

            Console.WriteLine("I have just printed...\"{0}\"", str);

        }

        public void printnumber()
        {

            Console.WriteLine("I have just printed...[{0}]", i);

        }

        public bool printnumber(int a,string str)
        {

            Console.WriteLine(a);
            Console.WriteLine(str);


            return false;
        }


        public bool printnumber(int a,bool b)
        {

            Console.WriteLine(a);
            Console.WriteLine(b);


            return !b;
        }
        ~Program()
        {
            //only necessary if you need to perform
            //    only operates when the object is No longer needed

        }


    }

    // this class serves to hold the main entry point and is the main class
    class mainclass
    {

        //main class always begins the program execution
        public static void Main(string[] args)
        {
            // we create instance of our class


            Program p3 = new Program();


            Console.WriteLine(p3.hasprintcode);//false

            Program p1 = new Program("print me");

            p1.i = 88;
            Console.WriteLine(p1.hasprintcode);//true
            //now we will call our method that we want to execute
            p1.printstring();
            p1.printnumber();

            p3.X = 100;
            p3.Y = 200;

            //Console.WriteLine(p3.x);
            //Console.WriteLine(p3.y);


            Console.WriteLine("---------------------------------------");

           Console.WriteLine(p1.printnumber(p3.X,"wow"));//100 wow false

           Console.WriteLine("---------------------------------------");
           Console.WriteLine(p1.printnumber(30,true));//30 true then false...


            Program p2 = new Program("anurag", 200);
            Console.WriteLine("printer--{0}:{1}", p2.i, p2.sprinter);
            Console.ReadLine();

        }
    }
}

No comments:

Post a Comment