作业帮 > 综合 > 作业

阅读下面C#代码,找出错误并改正.

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/06/11 19:33:54
阅读下面C#代码,找出错误并改正.
class A
{
private int x;
public A(int x)
{
this.x = x;
}
public int MyX
{
get
{
return x;
}
}
}
class B
{
public static void Main()
{
A b = new A(10);
b.MyX = 100;
Console.WriteLine(b.MyX);
}
}
将改正之后的代码写上就行了
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class A
{
private int x;
public A(int x)
{
this.x = x;
}
public int MyX
{
get
{
return x;
}
}
}
class B
{
public static void Main()
{
A b = new A(10);
//b.MyX = 100;
Console.WriteLine(b.MyX);
}
}
}