问个很笨的问题
本人是新鸟刚学C#不久~~~有很多还不懂~~~~~~望老鸟们多多指导哈比如这段代码:
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 tmpObj1 = new Class1();
tmpObj1.notstaticStr = "tmpObj1";
Class1 tmpObj2 = new Class1();
tmpObj2.notstaticStr = "tmpObj2";
//非静态变量通过对象进行访问,不同对象的同一非静态变量可以有不同的值
Console.WriteLine("tmpObj1's notstaticStr: {0}", tmpObj1.notstaticStr);
Console.WriteLine("tmpObj2's notstaticStr: {0}", tmpObj2.notstaticStr);
Console.ReadLine();
}
}
}
结果:
Class1's staticStr: Class
tmpObj1's notstaticStr: tmpObj1
tmpObj2's notstaticStr: tmpObj2
他什么时候该用大括号,还有怎么会知道引用这些变量等等
望老鸟门帮我上上课了!~~~谢谢了