[c#菜鸟]我想问一问IO 跟array 的一些问题
我正在做一个作业, 要我input(map.txt), 然后用array的方法显示出来奈何小弟愚钝, 试了很多次也没法运行, 求各位大大帮手
这是小弟写的:
map.txt如下:
6
8
XOOXOOOO
OOOOOOOO
XOOOOOOO
OOOOOOOO
XXXXXXXX
XXXOOOXX
using
namespace CinemaBookingSystem
{
public partial class Form1 : Form
{
const int buttonStartingPositionX = 40, buttonStartingPositionY = 80, buttonSizeIntegerX = 80, buttonSizeIntegerY = 40;
const string filename = "map.txt";
int rowInteger = 0;
int columnInteger = 0;
Button[,] myButtons;
string[,] myQueue;
public Form1()
{
InitializeComponent();
}
private void createButtons(int rowInteger, int columnInteger)
{
myButtons = new Button[rowInteger, columnInteger];
for (int i = 0; i < rowInteger; i++)
{
for (int j = 0; j < columnInteger; j++)
{
myButtons[i,j] = new Button();
myButtons[i,j].Size = new Size(buttonSizeIntegerX, buttonSizeIntegerY);
myButtons[i,j].Text = myQueue[i,j];
myButtons[i,j].FlatStyle = FlatStyle.Flat;
myButtons[i,j].Location = new Point(buttonStartingPositionX + buttonSizeIntegerX * i, buttonStartingPositionY);
Controls.Add(myButtons[i,j]);
}
}
}
private void readArray(string[,] X)
{
try
{
rowInteger = int.Parse(X[0,0]);
columnInteger = int.Parse(X[1,0]);
seatTextBox.Text = (rowInteger * columnInteger).ToString();
}
catch
{
MessageBox.Show("ERROR");
return;
}
myQueue = new string[rowInteger, columnInteger];
for (int i = 0; i < rowInteger; i++)
{
for (int j = 0; j < columnInteger; j++)
{
myQueue[i, j] = X[(i+1),(j+1)];
}
}
createButtons(rowInteger, columnInteger);
}
private void loadButton_Click(object sender, EventArgs e)
{
string[] fileContent;
try
{
fileContent = File.ReadAllLines(filename); Error 1 Cannot implicitly convert type 'string[]' to 'string[*,*]'
}
catch
{
MessageBox.Show("not found");
return;
}
readArray(fileContent);
}
}
}
[ 本帖最后由 be4u 于 2010-12-19 13:59 编辑 ]