各种情况下的方法调用

来源:互联网 发布:oppo软件开放平台 编辑:程序博客网 时间:2024/06/18 07:17
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Exeplems{   public class Class1    {        public static void Method()        {            Console.WriteLine("静态的方法可以直接调用!但是很耗资源!");        }        public void Method1()        {            Console.WriteLine("非静态的方法要创建对象来访问!");        }        public void Method2()        {            Method1();//同一类中的方法体可以直接访问静态和非静态的            Method();        }    }    class Program    {        static void Main(string[] args)        {            Class1.Method();//访问静态方法            Class1 obj = new Class1();//创建对象            obj.Method1();//访问非静态方法;必须是public的        }    }}
0 0
原创粉丝点击