簡體   English   中英

引用主要方法C#的外部變量

[英]Referencing outer variables for main method c#

我想知道如何在main方法中引用外部變量。 我已經做了一些工作,並且可以編譯,但是我似乎無法做“靜態字符串票”“靜態字符座” 到目前為止,這是我的代碼:

public class Cinema
{
    static int[,] cinema;
    static char[,] cinchar;
    static string ticket;
    static int[] row;
    static char seat;

    //--------------------------------
    static void Main(string[] args)
    {
        cinema = new int[10, 5];
        cinchar = new char[10, 5];
        //I want to reference the above **static string ticket** variable here
        row = new int[3];
        //I want to reference the above **static char seat** variable here

        for (int i = 0; i < 10; i++)
        {
            for (int j = 0; j < 5; j++)
            {
                cinchar[i, j] = (char)'*';
                cinema[i, j] = 0;

            }
        }
    }
}
public class Cinema
{
    static int[,] cinema;
    static char[,] cinchar;
    static string ticket;
    static int[] row;
    static char seat;

    //--------------------------------
    public static void Main(string[] args)
    {
        cinema = new int[10, 5];
        cinchar = new char[10, 5];
        ticket = "new ticket";
        //I want to reference the above **static string ticket** variable here
        row = new int[3];
        seat = 'a';
        Console.WriteLine("Ticket: " + ticket + ", Seat: " + seat.ToString());
        //I want to reference the above **static char seat** variable here

        for (int i = 0; i < 10; i++)
        {
            for (int j = 0; j < 5; j++)
            {
                cinchar[i, j] = (char)'*';
                cinema[i, j] = 0;

            }
        }
    }
}

產生票:新票,座位:a

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM