类 字段 方法 使用 重载 静态

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

namespace ConsoleApplication12
{
    class Program
    {
        
        static void Main(string[] args)
        {
            english c = new english();//实例化  
            student w = new student();

            int he = c.add(40, 50);
            //在这里引用了一个方法(x+y-3)
            Console.WriteLine("英语总成绩为" + he);
            //调取了student里面的 age字段
            Console.WriteLine("该类里面字段age=" + w.age);
            //定义变量为空
            chongzai x = null;
            //创建对象
            x = new chongzai();

            int u = x.add(100, 200);//调用类整数方法进行加减

            double p = x.add(2.3, 1.2);//调用类浮点想加减

            Console.WriteLine("100+200=" + u);
            Console.WriteLine("2.3+1.2" + p);
            stasic o = null;

            for (int i = 1; i < 100; i++)
            {
                o = new stasic();
                o.increase();
            }  
            Console.WriteLine("dynamicvar      " + o.dynamicvar);
            Console.WriteLine("staticvar       " + stasic.staticvar);
                Console.ReadLine()

                  ;


        }
      

    }
}



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

namespace ConsoleApplication12
{
    class student
    {
        //字段
        public int age = 18;

        public string sn = "12345";


    }
    //方法
    public class english
    {
        public int add(int x, int y)
        {
            return x + y - 3;

        }
    }
    //方法重载  
    public class chongzai
    {
        public int add(int x, int y)
        {
            return x + y;

        }
        public double add(double x, double y)
        {
            return x + y;

        }


    }
    class stasic//类静态成员
    {
        public static int staticvar = 0;//静态字段
        public int dynamicvar = 0;
        public void increase()
        {
            staticvar++;
            dynamicvar++;
        }
    }
}

  

posted @ 2015-09-24 00:37  人走茶亦凉  阅读(284)  评论(0编辑  收藏  举报