jaxad0127
0
Q:

how to get the last element in an array in c#

var lastItem = integerList.Last();
9
string[] str = new string[] {"Java","HTML","jQuery"};
Console.WriteLine("Last element: "+str[str.Length - 1])
5
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]);
   }
}
4
int[] somearray  = new int[4] {0, 1, 34, 2}
int lastelement = somearray[somearray - 1];
0
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]);
   }
}
0

New to Communities?

Join the community