按产量 return 填充 table

Filling table by yield return

我一个月前开始使用 C# 进行冒险。你能帮我解决下面的问题吗? 如何将Yieldreturn得到的结果正确插入到table中?就结果而言,我得到的 table 由上次生成的相同值 (10+5=15) 填充。我需要的是通过 yield return 函数逐步生成一系列结果。

public class Obliczenia
{
   // double P1, P2, V, S, R, P1a, Sa, Va;
   public IEnumerable<double> Wyniki
   {
       get
       {
           for (double Rf = 0; Rf <= 10; Rf += 1)
           {
               yield return Rf + 5; // finally here will be more complicated equation
           }
       }
   }
}


string[] tablica1 = new string[100];
Obliczenia o = new Obliczenia();

foreach (double wynik in o.Wyniki)
{
   for (int i = 0; i < 9; ++i)
   {
       tablica1[i] = wynik.ToString();  // I think, something wrong is here.
   }
}

我想这就是你想要的:

string[] tablica1 = new string[100];
Obliczenia o = new Obliczenia();

var k = 0;

foreach (double wynik in o.Wyniki)
{                
    tablica1[k] = wynik.ToString();
    k++;                               
}