1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace Exeplems
7 {
8 public class Class1
9 {
10 public static void Method()
11 {
12 Console.WriteLine("静态的方法可以直接调用!但是很耗资源!");
13 }
14 public void Method1()
15 {
16 Console.WriteLine("非静态的方法要创建对象来访问!");
17 }
18 public void Method2()
19 {
20 Method1();//同一类中的方法体可以直接访问静态和非静态的
21 Method();
22 }
23 }
24 class Program
25 {
26 static void Main(string[] args)
27 {
28 Class1.Method();//访问静态方法
29 Class1 obj = new Class1();//创建对象
30 obj.Method1();//访问非静态方法;必须是public的
31 }
32 }
33 }