Here is simple way of getting list of item IDs present in SPListItemCollection using LINQ:
Remember to include System.Linq namespace, otherwise you will get an error:
Microsoft.SharePoint.SPListItemCollection' does not contain a definition for 'Cast' and no extension method 'Cast' accepting a first argument of type 'Microsoft.SharePoint.SPListItemCollection
using (SPSite site = new SPSite("http://sp2010:900"))
{
SPWeb web = site.RootWeb;
SPList list = web.Lists["ListTitle"];
int[] itemIds = list.GetItems().Cast<SPListItem>().Select(i => i.ID).ToArray();
}
Remember to include System.Linq namespace, otherwise you will get an error:
Microsoft.SharePoint.SPListItemCollection' does not contain a definition for 'Cast' and no extension method 'Cast' accepting a first argument of type 'Microsoft.SharePoint.SPListItemCollection