二维数组
对于数组中的每个元素,我需要一个唯一的标识符,例如 Seat1、Seat2、Seat 3……一直到数组长度的末尾。
目前我已经完成了以下操作:
int rows = 10, cols = 10;
bool[ , ] seatArray = new bool[rows , cols]; //10 rows, 10 collums
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++ )
{
seatArray[i, j] = false;
}
foreach (bool element in seatArray)
{
Console.WriteLine("element {0}", element);
}
}
这只是在控制台中显示“Element False”x 100。
我需要将“Element”替换为 Seat1、Seat2、Seat3... 到数组长度的末尾。
任何帮助将不胜感激!
谢谢你!
For each element in the array I need a unique identifier such as Seat1, Seat2, Seat 3....... all the way to the end of the length of the array.
currently I have done the following:
int rows = 10, cols = 10;
bool[ , ] seatArray = new bool[rows , cols]; //10 rows, 10 collums
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++ )
{
seatArray[i, j] = false;
}
foreach (bool element in seatArray)
{
Console.WriteLine("element {0}", element);
}
}
this simply just says "Element False" x 100 in the console.
i need to replace "Element" with Seat1, Seat2, Seat3....to the end of the array length.
any help will be much appreciated!
thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
创建一个具有 ID 和 Occupied(?) 属性的 Seat 类(或结构,如果更合适的话)。制作一个这种类型的数组。
Create a Seat class (or structure, if more appropriate) with ID and Occupied(?) properties. Make an array of this type.
不知道这是什么语言,所以不知道语法,但只需做一些外部计数器来对它们进行编号
,每次将每个计数器设置为 false 时,它都会说 false,不要使用 bool,或者编写一个类来保存 true false 和数字信息
no idea what language this is so idk the syntax but just do some external counter to number them
that just says false every time you set every one to false, dont use a bool, or write a class to hold the true false and number info
tvanfosson,我正在努力使您的编码工作正常,iv 将其放入我的主要方法中的一个新类中,请参见下文:
这是正确的吗,因为我似乎收到了很多语法错误,
谢谢!
tvanfosson, i am struggling to make your coding work, iv put it into a new class off my main method see below:
is this correct as i seem to be receiving a lot of syntax errors
thank you!