Wednesday 4 November 2009

System.Data.DataRow indexer complexity

Have you ever wonder what is the time complexity of accessing DataRow by column name? Unfortunately, this information is not specified on MSDN.

So the obvious answer would be O(n). We might think that there is iteration on data columns and in worst case it would iterate on all of them.

The actual answer can be discovered by looking on System.Data.dll using Reflector. We'll see there, that there is an access to Hashtable of column names by name, which obviosly take O(1).

So the overall complexity of the following would be O(1).

object data = row["CUSTOMER"];