引用主方法的外部变量
本文关键字:外部 变量 方法 引用 | 更新日期: 2023-09-27 18:16:47
我想知道如何在主方法中引用外部变量。我已经设法做了一些,它编译,但我似乎不能做"静态字符串票证" &"静态字符位置"。这是我到目前为止的代码:
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