C#: Lists of Other Types [14 of 19]

Play C#: Lists of Other Types [14 of 19]

The Discussion

  • User profile image
    sarangjajoo
    Kendra...you are so so so so pretty. I just keep on seeing your videos again and again despite knowing about the topics. You are love.
  • User profile image
    maasr
    Thanks for the great tutorial. Below is my code :)


    static void ExploreListInt()
    {
    var fibonacciNumbers = new List { 1, 1};
    int stop = 20;
    for (int i = 2; i < stop; i++)
    {

    int pos1 = Math.Max(i - 1, 0);
    int pos2 = Math.Max(i - 2,0);

    //Console.WriteLine($"{pos1} & {pos2}");

    fibonacciNumbers.Add((fibonacciNumbers[pos1]) + (fibonacciNumbers[pos2]));

    }

    foreach (var item in fibonacciNumbers)
    Console.WriteLine(item);
    }
  • User profile image
    Buelent
    @maasr:
    var fibonacciNumbers = new List { 1, 1 };

    for (int i = 2; i < 20; i++)
    {
    int pos1 = i - 1;
    int pos2 = i - 2;

    fibonacciNumbers.Add((fibonacciNumbers[pos1]) + (fibonacciNumbers[pos2]));
    }

    foreach (var item in fibonacciNumbers)
    Console.WriteLine(item);

    This should be your code. There is no need for the Math.Max Methode, also the stop variable is unnecessary. But I like your solution and idea, thank you for sharing it :)

Add Your 2 Cents