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

      

  • 相关阅读:
    新项目调试思路
    cmstop核心
    jquery获取li中的各项属性值attr
    mysql表设计
    SQLServer系统表使用简介(sysobjects、syscolumns、syscomments等)转载
    死锁查询和处理
    this 关键字的用法
    C# 线程
    C# WCF的通信模式
    C# WCF之用接口创建服务契约、部署及客户端连接
  • 原文地址:https://www.cnblogs.com/hanke123/p/4834019.html
Copyright © 2011-2022 走看看