What is the time complexity of accessing a column by its name in an instance of DataRow?
object Foo(DataRow row, string columnName)
{
// What is the time complexity of 开发者_JAVA百科the below line O(1) / O(n) / ?
return row[columnName];
}
I took a peek with Reflector and can confirm that the code in question has a time complexity of O(1). The actual data is stored in DataColumn instances using a plain old array indexed by record number...one array per column. The DataColumn is obtained from the name via a Hashtable and the record number is obtained directly from the DataRow instance. So you have a hash table lookup and an array lookup both of which are O(1).
精彩评论