Helper functions to get last element in collection

Below are couple simple helper functions to get last element in collection:

 public static Object LastElement(Object[] myArr)
        {
            if( IsNullOrEmpty(myArr))
            {
                return null;
            }
            return myArr[myArr.Length-1];
        }

        public static DataRow GetLastRow(DataTable tbl)
        {
            if (tbl == null) { throw new NullReferenceException(“tbl is null”); }
            if (tbl.Rows.Count == 0)
            {
                return null;
            }
            return tbl.Rows[tbl.Rows.Count – 1];
        }

Advertisements