例如,在A节中,我有一个随机数,在b节中,我想把这个随机数乘以2,但是它必须在一个函数中,然后c节:必须加10,等等。我想这对你们来说很简单。我确信我正在编写非常愚蠢的代码,但我不是一个程序员。
谢谢。
class Program
{
static void Main(string[] args)
{
Boot boot = new Boot();
Game game = new Game();
Console.WriteLine("Matrix Lengte: " + game.Matrix);
Console.WriteLine("Lengte boot: " + boot.Lengte);
Console.ReadLine();
class Game
{
private Boot boot;
private int matrix;
public int Matrix
{
get { return matrix; }
set { matrix = value; }
}
public Game()
{
matrix= boot.Lengte*2;
}
internal Boot Boot
{
get { return boot; }
set { boot = value; }
}发布于 2013-12-09 13:01:41
默认情况下,字段有其默认值,即引用类型的null。因此,只需添加boot初始化:
public Game()
{
boot = new Boot(); // or pass via constructor parameter
matrix = boot.Lengte * 2;
}https://stackoverflow.com/questions/20471324
复制相似问题