谁能帮我解释下列C#程序是什么意思?

来源:百度知道 编辑:UC知道 时间:2024/06/15 12:02:16
using System;
using System.Collections.Generic;
using System.Text;

namespace 实验2_1
{
class SataticTest
{ public static int sta1 = 10;
public int a2 = 10;
}
class Program
{
public static void Main()
{
SataticTest A, B; //1
A = new SataticTest();
B = new SataticTest(); //2
SataticTest.sta1 = SataticTest.sta1 + 10; //3
A.a2 = A.a2 + 10; //4
SataticTest.sta1 = SataticTest.sta1 + 10;
B.a2 = B.a2 + 10; //5
Console.WriteLine("SataticTest.sta1={0},A.a2={1}",SataticTest.sta1,A.a2); //6
Console.WriteLine("SataticTest.sta1={0},B.a2={1}",SataticTest.sta1,B.a2);
Console.ReadLine();
}

SataticTest A, B; //1 定义两个类变量,
A = new SataticTest();
B = new SataticTest(); //2 将类变量实例化
SataticTest.sta1 = SataticTest.sta1 + 10; //3 静态的变量可以通过类名直接调用其属性.==B.sta1

A.a2 = A.a2 + 10; //4 修改属性值, 或者说是修改A类的成员变量a2的值
SataticTest.sta1 = SataticTest.sta1 + 10;
B.a2 = B.a2 + 10; //5 修改属性值,
Console.WriteLine("SataticTest.sta1={0},A.a2={1}",SataticTest.sta1,A.a2); //6 将SataticTest.sta1及A.a2的值从控制台输出

以上似乎在说明确程序中 所谓的静态是怎么回事?运行程序观察输出的两个值,
一个是实例化后,一个是直接调用其类名访问其属性