有两个类 类A和类B 类A有变量i=0 通过类A的构造函数实例化类B 然后通过类B的构造函数改变i的值为5 输出i

来源:百度知道 编辑:UC知道 时间:2024/05/25 02:39:33
有两个类 类A和类B 类A有变量public int i=1; 通过类A的构造函数实例化类B 然后通过类B的构造函数改变i的值为5 输出i

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace Test
{
class Program
{
static void Main(string[] args)
{
A classA = new A();
}
}

class A
{
public static int i;
public A()
{
B classB = new B();
}
}
class B
{
public B()
{
A.i = 5;
Console.WriteLine(A.i);
Console.Write("任意键退出");
Console.Read();
}
}
}

using System;
using System.Collections.Generic;

namespace aaa
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
A a=new A();
Console.