how to know if my value is the last of array c# code example

Example 1: c# check if element is last in list

foreach (var x in things)
	{
        //Do stuff
    	if (x == things.Last()) // Do Stuff only for the last item 
 	}

Example 2: last elemnet of array in c#

using System;

public class Demo {
   public static void Main() {
      string[] str = new string[] {
         "Java",
         "HTML",
         "jQuery",
         "JavaScript",
         "Bootstrap"
      };
      Console.WriteLine("Array...");
      foreach(string res in str) {
         Console.WriteLine(res);
      }
      Console.WriteLine("Last element: "+str[str.Length - 1]);
   }
}