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];
        }

posted @ Wednesday, December 03, 2008 10:06 PM

Print

Comments on this entry:

No comments posted yet.

Your comment:



 (will not be displayed)


 
 
 
 
 

Live Comment Preview:

 
«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345