C#, Application console, Virtual Studio 2015, Paralelles: Windows 8.1.Pourquoi chaque ligne de la sortie du fichier .txt se termine-t-elle par 'System.int32'? C#
Le code est le suivant:
class txt_program
{
public void txt()
{
/* 0 */
int[] M_array_0 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/* 1 */
int[] M_array_1 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/* 2 */
int[] M_array_2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// etc.
// the M matrix
int[][] M = { M_array_0, M_array_1, M_array_2, M_array_3, M_array_4,
M_array_5, M_array_6, M_array_7, M_array_8, M_array_9, M_array_10,
M_array_12, M_array_13 };
// the time pick is beeing called into this item.
Time_pick_2 T2 = new Time_pick_2();
// the if loop making
// 0
if (T2.M_build_0() == true)
{
int nr_0 = 0;
for (int i = nr_0; i < nr_0 + 2; i++)
{
M[1][i] = M_array_0[i] + 1;
}
}
// 1
else if (T2.M_build_1() == true)
{
int nr_1 = 1;
for (int i = nr_1; i < nr_1 + 2; i++)
{
M[1][i] = M_array_1[i] + 1;
}
}
// 2
else if (T2.M_build_2() == true)
{
int nr_2 = 2;
for (int i = nr_2; i < nr_2 + 2; i++)
{
M[2][i] = M_array_2[i] + 1;
}
}
// etc.
using (StreamWriter SW = new StreamWriter(@"txt.txt"))
{
// the loops creating the .txt-file.
for (int i = 0; i < M.GetLength(0); i++)
{
for (int a = 0; a < 13; a++)
{
SW.Write(" " + M[i][a]);
}
SW.WriteLine(M);
}
}
}
}
}
Comme pastebin:
La sortie est donnée comme:
0 0 0 0 0 0 0 0 0 0 0 0 0System.Int32[][]
0 1 1 0 0 0 0 0 0 0 0 0 0System.Int32[][]
0 0 0 0 0 0 0 0 0 0 0 0 0System.Int32[][]
// etc.
j'ai vérifié un autre post sur l'apparence off System.Int32[][]
mais dans tous les cas c'était le code qui ne générait pas de sortie sauf System.Int32[]
, ce qui signifiait que le code ne pouvait pas interpréter le for-loop
créant la sortie. Ici, la sortie correcte est affichée mais toujours avec la fin System.Int32[][]
. Pourquoi est-ce et qu'est-ce que je fais mal?
vous sortez le tableau après votre boucle interne: 'SW.WriteLine (M);' – Nico
@heinzbeinz bien oui je l'utilise pour faire un changement de ligne, que suggérez-vous t? –
Voir ma réponse. Vous pouvez simplement utiliser 'SW.WriteLine (" ")' – Nico