Archived
添加一个numberof用于访问特定索引下的索引器对象,不过这个有意义吗?
This commit is contained in:
@@ -166,6 +166,24 @@ namespace XericLibrary.Runtime.MacroLibrary
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region LinQ扩展
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取索引下的迭代器对象
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="list"></param>
|
||||||
|
/// <param name="index"></param>
|
||||||
|
/// <returns>当索引超出或其他原因导致没能找到对象时返回默认</returns>
|
||||||
|
public static T NumberOf<T>(this IEnumerable<T> list, int index)
|
||||||
|
{
|
||||||
|
var count = index;
|
||||||
|
foreach(var item in list)
|
||||||
|
if(0 < --count)
|
||||||
|
return item;
|
||||||
|
return default(T);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user