Search code examples
c#.netbase-class-libraryfcl

Is there any standard method to get array of objects from object with indexer by range of index keys?


As input i have object that implements IDataRecord(row of some abstract table), so it have indexer, and by giving it some integer i can retrive object of some type. As output my code must get some range of cells in that row as array of given type objects.

So I've written this method(yes, i know, it can be easly converted to extension method, but i don't need this, and also i don't really want to have this method visible outside of my class):

private static T[] GetRange<T>(IDataRecord row, int start, int length)
{
    var result = new List<T>();          

    for (int i = start; i < (start + length); i++)
    {
        result.Add((T)row[i]);
    }

    return result.ToArray();
}

It works fine, but this method logic seems like something very common. So, is there any method that can give same(or almost same) result in .NET Framework FCL/BCL?


Solution

  • Well.. Seem's like there is no such method in FCL/BCL