Help showing next and previous index C#

Hi all

I have a small snippet below, the problem is, I need a way of displaying the next and previous nodes/indexes from the current, though (@l //Previous and @l //Next) don’t show anything.

Wondering if anybody can help, maybe advise what I’m doing wrong and way the indexes aren’t showing? Previous and Next should show one of the vowels.

`string[] vowels = { "a", "e", "i", "o", "u" };
var names = new List<string>(vowels);

  foreach (var l in names.ToList())

  {

for (int i = 0; i < l.Count(); i++)

{
    var previousNode = l.ElementAtOrDefault(i - 1);

    if (previousNode != null)

      {

         @l //Previous

      }

    @l.ElementAt(i) //Current

    var nextNode = l.ElementAtOrDefault(i + 1);

    if (nextNode != null)

      {

          @l //Next

      }
}

}`

Barry

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.