Bonjour tous le monde si vous pouvez m'aider, j'ai un problème de conversion du formay string au format float voici mon code:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
 
namespace Sig_vallée_barrage
{
public partial class Form1 : Form
{
int nc, mc;
List<string[]> tableau = new List<string[]>();
List<int> liste_x = new List<int>();
List<int> liste_y = new List<int>();
public Form1()
{
InitializeComponent();
}
 
private void button1_Click(object sender, EventArgs e)
{
Stream myStream;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
 
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 2;
openFileDialog1.Multiselect = false;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
// Lecture du fichier selectionner
using (System.IO.StreamReader file = new System.IO.StreamReader(openFileDialog1.OpenFile()))
{
nc = Convert.ToInt16(file.ReadLine().Split(' ')[9].ToString());
mc = Convert.ToInt16(file.ReadLine().Split(' ')[9].ToString());
double xc = Convert.ToDouble(file.ReadLine().Split(' ')[5].ToString());
double yc = Convert.ToDouble(file.ReadLine().Split(' ')[5].ToString());
double zc = Convert.ToDouble(file.ReadLine().Split(' ')[6].ToString());
double vc = Convert.ToDouble(file.ReadLine().Split(' ')[2].ToString());
int n = 1;
while (!file.EndOfStream)
{
string[] x = file.ReadLine().Split(' ');
tableau.Add(x);
 
for (int i = 1; i <= x.Length; i++)
{
 
float valeur = float.Parse(x[i]);
 
 
if (valeur == 1)
{
liste_x.Add(n);
liste_y.Add(i);
}
 
}
 
n = n + 1;
label3.Text = x.Length.ToString();
}
 
}
label2.Text = tableau.Count.ToString();
 
}
}
}
}
}
l'erreur est: le format de la chaine d'entrée est incorrect.
et merci d'avance