zoukankan      html  css  js  c++  java
  • 类 字段 方法 使用 重载 静态

    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++;
            }
        }
    }
    

      

  • 相关阅读:
    const变量指针赋值给非const类型的指针运行结果
    嵌套结构可以访问外部结构的私有成员吗?
    几种cms的介绍
    中国互联网网站尴尬排行榜[转]
    如何跨域来同步不同网站之间的Cookie
    CMS整站程序整理
    vs 设置断点
    ASP.NET 4中的SEO改进
    VSS演示
    发生一个未处理的异常 脚本调试 错误号2912
  • 原文地址:https://www.cnblogs.com/hanke123/p/4834019.html
Copyright © 2011-2022 走看看