Generic in Asp.net 2.0, Asp.net Developer in India
This is how we can convert IList to a generic List<> collection
 | Convert IList to Generic |
| /// <summary>
| | 1: /// Convert IList to Generic List<> Example: BasicFunctions.ConvertToListOf<MyObject>(IListObject)
| | 2: /// </summary>
| | 3: /// <typeparam name="T"></typeparam>
| | 4: /// <param name="iList"></param>
| | 5: /// <returns></returns>
| | 6: public static List<T> ConvertToListOf<T>(System.Collections.IList iList)
| | 7: {
| | 8: List<T> result = new List<T>();
| | 9:
| | 10: foreach (T value in iList)
| | 11: result.Add(value);
| | 12:
| | 13: return result;
| | 14: }
| | 15: |
|
Find and FindAll matching object in any generic List<> collection
 | Find FindAll in generic List object |
| using System;
| | 1:using System.Collections.Generic;
| | 2:
| | 3:namespace Arindam
| | 4:{
| | 5: public class FindFindAll
| | 6: {
| | 7: // List<>.Find implementation
| | 8: List<MyCustomObject> MyCustomObjectList = new List<MyCustomObject>();
| | 9: MyCustomObject _obj = MyCustomObjectList.Find((delegate(MyCustomObject _a) { bool b = (_a.ParentId == _row.ChildId) ? true : false; return b; }));
| | 10:
| | 11:
| | 12: // List<>.FindAll implementation
| | 13: List<MyCustomObject> _objCustomObjectList = MyCustomObjectList.FindAll((delegate(MyCustomObject _a) { bool b = (_a.Id == 1 || _a.Id== 2) ? true : false; return b; }));
| | 14: }
| | 15:}
| | 16: |
|
Example of generic parameter
 | Find FindAll in generic List object |
Specified file can't be found
|
Asp.net, Ado.net, .Net Remoting, .Net
Webservice, SQL, XML, XSLT, WCF, WPF, WWF NHibernate, Ajax, Jquery, DHTML