gpt4 book ai didi

c# - 循环中的性能差异

转载 作者:太空宇宙 更新时间:2023-11-03 19:35:16 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Difference between declaring variables before or in loop?

当我写这样的东西时(考虑从数据库加载数万或数十万行到 Foo 对象的集合中),是否存在任何(或任何显着的)性能差异:

...
Foo myFoo;

while(reader.Read())
{
myFoo = new Foo();
myFoo.SomeProperty = reader.GetValue(0);
...
fooCollection.Add(myFoo);
}

或者这个

...

while(reader.Read())
{
Foo myFoo = new Foo();
myFoo.SomeProperty = reader.GetValue(0);
...
fooCollection.Add(myFoo);
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com