using System;
using System.Collections.Generic;
using System.Text;
namespace Example01
{
class Program
{
class Class1
{
public static String staticStr = "Class";
public String notstaticStr = "Obj";
}
static void Main(string[] args)
{
Console.WriteLine("Class1's staticStr: {0}", Class1.staticStr); //静态变量通过类进行访问,该类所有实例的某一静态变量都是同一个值 ,输出Class1's staticStr: Class
Class1 tmpObj1 = new Class1();
tmpObj1.notstaticStr = "tmpObj1";
Class1 tmpObj2 = new Class1();
tmpObj2.notstaticStr = "tmpObj2";
Console.WriteLine("tmpObj1's notstaticStr: {0}", tmpObj1.notstaticStr); //非静态变量通过对象进行访问,不同对象的同一非静态变量可以有不同的值,输出tmpObj1's notstaticStr: tmpObj1
Console.WriteLine("tmpObj2's notstaticStr: {0}", tmpObj2.notstaticStr); //非静态变量通过对象进行访问,不同对象的同一非静态变量可以有不同的值,输出tmpObj2's notstaticStr: tmpObj2
Console.ReadLine();
}
}
} |