静态变量举例
来源:互联网 发布:asp自动发卡源码 编辑:程序博客网 时间:2024/06/07 19:20
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace 静态{ class Program { static void Main(string[] args) { D d1 = new D(); D d2 = new D(); d1.SetVars(2, 4); d1.Display("d1");//2,4 d2.SetVars(15, 17); d2.Display("d2");//15,17 d1.Display("d1");//2,17 Console.ReadLine(); } } class D { int myInt1; static int myInt2;//静态 public void SetVars(int v1,int v2)//设置值 { myInt1 = v1; myInt2 = v2; } public void Display(string str) { Console.WriteLine("{0}:myInt1={1},myInt2={2}",str,myInt1,myInt2); } } }