Вернуть несколько значений из метода - C# (179619)
Формулировка задачи:
Добрый день! Подскажите есть метод, который считывает из файла данные
Но при вызове выдает только последнюю строчку в файле, как вернуть несколько значений сразу же. Вот так вызываю
int Shirina(StreamReader sr)
{
Regex reg_visota = new Regex(@"\b(\d+\W?шмм)");
while (!sr.EndOfStream)
{
string input = sr.ReadLine();
Match match_shirina = reg_visota.Match(input);
while (match_shirina.Success)
{
string input3 = match_shirina.Groups[1].Value;
if (!input3.Contains("вмм"))
{
char[] mychar2 = { 'ш', 'м', 'м' };
string inp_shirina = input3.TrimEnd(mychar2).Trim();
inp_shirina_txt = Convert.ToInt32(inp_shirina);
inp_shirina_textbox = Convert.ToInt32(txt_shirina.Text);
//MessageBox.Show("ширина " + inp_shirina_txt.ToString());
match_shirina = match_shirina.NextMatch();
}
}
// sr.Close();
}
return inp_shirina_txt;
} Encoding windows1251 = Encoding.GetEncoding("Windows-1251");
StreamReader sr = new StreamReader(openFileDialog1.FileName, windows1251);
MessageBox.Show(Visota(sr).ToString());Решение задачи: «Вернуть несколько значений из метода»
textual
Листинг программы
List<int> Shirina(StreamReader sr)
{
List <int> list=new List<int>();
Regex reg_visota = new Regex(@"\b(\d+\W?шмм)");
while (!sr.EndOfStream)
{
string input = sr.ReadLine();
Match match_shirina = reg_visota.Match(input);
while (match_shirina.Success)
{
string input3 = match_shirina.Groups[1].Value;
if (!input3.Contains("вмм"))
{
char[] mychar2 = { 'ш', 'м', 'м' };
string inp_shirina = input3.TrimEnd(mychar2).Trim();
list.add( Convert.ToInt32(inp_shirina));
inp_shirina_textbox = Convert.ToInt32(txt_shirina.Text);
//MessageBox.Show("ширина " + inp_shirina_txt.ToString());
match_shirina = match_shirina.NextMatch();
}
}
// sr.Close();
}
return list;
}