Не преобразовывается string в double и не вносится в массив - C#
Формулировка задачи:
Суть такова, при попытке преобразовать строковую переменную в double и внести её в массив программа выдает ошибку "Additional information: Входная строка имела неверный формат." в string находятся переменные который должны подходить к типу double(или я совсем тупой) собственно проблема возникает в данной части программы:
так же пробовал сделать так
в переменной Суть собственно говоря в том что бы значения procent вносились в массив а затем из него находило минимальное и максимальное значение, если есть какой то другой способ это сделать буду так же очень благодарен.
P.S. Я слегка совсем тупой в C# по сути меньше недели
P.S.S. да понимаю что есть куча тем с преобразованием данных переменных, но я так и не смог понять как изменить кода...
double[] myArray = new double[5];
myArray[0] = Convert.ToDouble(procent);
myArray[1] = Convert.ToDouble(procent1);
myArray[2] = Convert.ToDouble(procent2);
myArray[3] = Convert.ToDouble(procent3);
myArray[4] = Convert.ToDouble(procent4); double[] myArray = new double[5];
myArray[0] = double.Parse(procent);
myArray[1] = double.Parse(procent1);
myArray[2] = double.Parse(procent2);
myArray[3] = double.Parse(procent3);
myArray[4] = double.Parse(procent4);procent
находятся значения типа -1.20, 6.50 и т.д. по сути нечего выходящего за пределы типа... полностью программа(там всё очень плохо но оно работает, так что я не трогаю):using System;
using System.Collections;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void button1_Click(object sender, EventArgs e)
{
WebClient client = new WebClient();
string adress = "http://economictimes.indiatimes.com/indian-oil-corporation-ltd/stocks/companyid-11924.cms";
string newLine = client.DownloadString(adress);
string result;
string procent;
result = Regex.Match(newLine, @"<div class=""value"" id=""nseTradeprice"">(\-?\d+(\.\d{0,})?)</div>").Groups[1].Value;
procent = Regex.Match(newLine, @"<span id=""nseNetchange"">(\-?\d+(\.\d{0,})?)</span>").Groups[1].Value;
textBox1.Text = result;
textBox2.Text = "Indian Oil Corporation Ltd.";
textBox3.Text = procent;
string adress1 = "http://economictimes.indiatimes.com/reliance-industries-ltd/stocks/companyid-13215.cms";
string newLine1 = client.DownloadString(adress1);
string result1;
string procent1;
result1 = Regex.Match(newLine1, @"<div class=""value"" id=""nseTradeprice"">(\-?\d+(\.\d{0,})?)</div>").Groups[1].Value;
procent1 = Regex.Match(newLine1, @"<span id=""nseNetchange"">(\-?\d+(\.\d{0,})?)</span>").Groups[1].Value;
textBox4.Text = "Reliance Industries Ltd.";
textBox8.Text = result1;
textBox12.Text = procent1;
string adress2 = "http://economictimes.indiatimes.com/bharat-petroleum-corporation-ltd/stocks/companyid-11941.cms";
string newLine2 = client.DownloadString(adress2);
string result2;
string procent2;
result2 = Regex.Match(newLine2, @"<div class=""value"" id=""nseTradeprice"">(\-?\d+(\.\d{0,})?)</div>").Groups[1].Value;
procent2 = Regex.Match(newLine2, @"<span id=""nseNetchange"">(\-?\d+(\.\d{0,})?)</span>").Groups[1].Value;
textBox5.Text = "Bharat Petroleum Corporation Ltd.";
textBox9.Text = result2;
textBox13.Text = procent2;
string adress3 = "http://economictimes.indiatimes.com/hindustan-petroleum-corporation-ltd/stocks/companyid-12078.cms";
string newLine3 = client.DownloadString(adress3);
string result3;
string procent3;
result3 = Regex.Match(newLine3, @"<div class=""value"" id=""nseTradeprice"">(\-?\d+(\.\d{0,})?)</div>").Groups[1].Value;
procent3 = Regex.Match(newLine3, @"<span id=""nseNetchange"">(\-?\d+(\.\d{0,})?)</span>").Groups[1].Value;
textBox6.Text = "Hindustan Petroleum Corporation Ltd.";
textBox10.Text = result3;
textBox14.Text = procent3;
string adress4 = "http://economictimes.indiatimes.com/tata-motors-ltd/stocks/companyid-12934.cms";
string newLine4 = client.DownloadString(adress4);
string result4;
string procent4;
result4 = Regex.Match(newLine4, @"<div class=""value"" id=""nseTradeprice"">(\-?\d+(\.\d{0,})?)</div>").Groups[1].Value;
procent4 = Regex.Match(newLine4, @"<span id=""nseNetchange"">(\-?\d+(\.\d{0,})?)</span>").Groups[1].Value;
textBox7.Text = "Tata Motors Ltd.";
textBox11.Text = result4;
textBox15.Text = procent4;
double[] myArray = new double[5];
myArray[0] = Convert.ToDouble(procent);
myArray[1] = Convert.ToDouble(procent1);
myArray[2] = Convert.ToDouble(procent2);
myArray[3] = Convert.ToDouble(procent3);
myArray[4] = Convert.ToDouble(procent4);
}
}
}Решение задачи: «Не преобразовывается string в double и не вносится в массив»
textual
Листинг программы
myArray[0] = Convert.ToDouble(procent.Replace(".", ","));