例如,在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; }
}
Run Code Online (Sandbox Code Playgroud)
默认情况下,字段具有默认值,null用于引用类型.所以,只需添加boot初始化:
public Game()
{
boot = new Boot(); // or pass via constructor parameter
matrix = boot.Lengte * 2;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
165 次 |
| 最近记录: |