优化 DataReader 结果:将值保留为对象的结果是什么?

Optimizing DataReader Results: what is the concequence of leaving the values as objects?

var list = new List<object[]>();
var fieldCount = reader.FieldCount;
while(reader.Read()) {
    var array = new object[fieldCount];
    reader.GetValues(array);
    list.Add(array);
}

鉴于上面的简单代码片段。并假设正在检索的值是值类型的混合。

Is there any speed advantage if you knew the types of each column before hand, and could properly call there typed methods to get (all) their values?

是的。因为您的替代方案正在检查适当的类型,例如:

if (obj is string)
{
 //Do string things
}
else if (obj is int)
{
 //Do int things
}

当知道类型时,简单地转换:

string t = (string) obj;

Or is getting the typed values slowing the overall read process down?

没有。事实上,你不能比转换为正确的类型更快。

What trade-offs if any are there when leaving the data in object arrays, vs storing them in a typed entity?

将它们存储在对象数组中会占用更多内存,因为 value-types 被装箱为对象。