Typedef equivalent in C #?

I know this exact question has been asked , but the solution posted there does not seem to work for me. Here is the code I'm trying:

namespace ConsoleApplication5
{
    class Program
    {
        enum Tile { Empty, White, Black };
        using Board = Tile[8,8];

And the error I get:

Invalid 'using' token in class member declaration, structure or interface

It seems that the use clause should be moved outside the class Program, but my listing Tiledoes not exist there. So how should I do this?

+3
source share
3 answers

It sounds like you're trying to use a name to represent a specific way to create an instance of an array Tile[,].

Why not just declare a method that does this?

Tile[,] GetBoard()
{
    return new Tile[8, 8];
}

, , ( ), Board Tile[,] :

public class Board
{
    private Tile[,] tiles = new Tile[8, 8];

    public static implicit operator Tile[,](Board board)
    {
        return board.tiles;
    }
}

:

Tile[,] board = new Board();
+7

using.

, "", .

+6

, using . , , # .

, Board , , :

public class Board
{
    public Tile[,] Tiles = new Tile[8,8];
}

, new Board(), 8x8.

+2

Source: https://habr.com/ru/post/1762236/


All Articles