c# index array with string code example

Example 1: C# array index tostring

string[] greetings = new string[] {"hi", "hello", "hey there"};
Console.WriteLine(greetings[2].ToString());

Example 2: find index of string in a list C#

using System;
using System.Collections.Generic;
public class Program {
   public static void Main() {
      List < string > myList = new List < string > () {
         "Football",
         "Soccer",
         "Tennis",
      };

      // finding index
      int index = myList.FindIndex(a => a.Contains("Tennis"));

      // displaying index
      Console.WriteLine("List Item Tennis Found at index: " + index);
   }
}