CSharp examples for System.Collections.Generic:IEnumerable
Get the last item from an IEnumerable
using System.Text; using System.Collections.Generic; using System.Collections; using System;//w ww.j a v a 2s . co m public class Main{ /// <summary> /// Get the last item from an IEnumerable /// </summary> /// <param name="collection"></param> /// <returns>return null if the collection is empty</returns> /// <remarks> /// This method depends on the sequence of the collection, /// if the collection does not have a sequence, then it is unpreditable that which item will be returned. /// </remarks> public static object GetLast(IEnumerable collection) { object retVal = null; IEnumerator en = collection.GetEnumerator(); while (en.MoveNext()) retVal = en.Current; return retVal; } }