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

      

  • 相关阅读:
    eslint 的 env 配置是干嘛使的?
    cookie httpOnly 打勾
    如何定制 antd 的样式(theme)
    剑指 Offer 66. 构建乘积数组
    剑指 Offer 65. 不用加减乘除做加法
    剑指 Offer 62. 圆圈中最后剩下的数字
    剑指 Offer 61. 扑克牌中的顺子
    剑指 Offer 59
    剑指 Offer 58
    剑指 Offer 58
  • 原文地址:https://www.cnblogs.com/hanke123/p/4834019.html
Copyright © 2011-2022 走看看