I add the method for adding Ienumerable collection to Icollection.
public static ICollection<T> AddTo<T>(this IEnumerable<T> list,ICollection<T> collection) {
foreach (T item in list) {
collection.Add(item);
}
return collection;
}
But at first time initialized collection variable as null.Then i am getting "Object reference not found error"please tell me how to add Ienumerable list data to Icollection properly?
EDIT:
ICollection<UserInApplication> userInAppRole=null;
IEnumerable<UserInApplication> result=null;
result = _userService.UserInApplicationRoles(iAppRoleId, collection["displayName"]).AsEnumerable();
userInAppRole = Extensions.AddTo<UserInApplicationRole>(result,userInAppRole);
You are not initializing your collection. And extension methods can be called in a better way.