Reputation: 13
I would like the loop to start from the second element and to end before the last one. So that I can set the first and last one to constant value.
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
Console.Write($"A[{i},{j}] = ");
tab[i, j] = double.Parse(Console.ReadLine());
}
}
Upvotes: 0
Views: 1323
Reputation: 431
Why don't do something like that?
for (int i = 1; i < n - 1; i++)
{
//your code
}
Upvotes: 1
Reputation: 39966
You can use LINQ simply:
var result = yourArray.Skip(1).SkipLast(1).Prepend(theConstValue)
.Append(theConstValue).ToArray();
The Prepend
, Adds a value to the beginning of the sequence.
The Append
, Appends a value to the end of the sequence.
Upvotes: 2