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

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted @ Wednesday, December 03, 2008 10:06 PM
Print

Comments on this entry:

No comments posted yet.

Your comment:



(not displayed)


 
 
 
 
 

Live Comment Preview:

 
«February»
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910