Hi all,
If I have a expensive public property that exposes a collection, say
via a call to a database:
public ArrayList Complex
{
get
{
//expensive call to db
return DbResult;
}
}
and use this in a foreach:
foreach( object o in Complex )
{
...
}
Will the clr call Complex only once, and save a reference to the
direct variable actually exposed, or will it execute the code in the
get routine each iteration?
Thanks in advance,
Ben Joldersma
Sr. Software Engineer,
Citadel Media, Inc. 4 1645
Benjamin Joldersma <be**@theinsiders.com> wrote:
<snip> Will the clr call Complex only once, and save a reference to the direct variable actually exposed, or will it execute the code in the get routine each iteration?
It calls it once, and gets an iterator. So no, you don't need to worry
about the time it takes to evaluate that.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Hi Benjamin,
It call it once.
This is VERY easy to check ( I just did it ), just put a breakpoint inside
the get method , you will see it only enters once.
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Benjamin Joldersma" <be**@theinsiders.com> wrote in message
news:8f**************************@posting.google.c om... Hi all,
If I have a expensive public property that exposes a collection, say via a call to a database:
public ArrayList Complex { get { //expensive call to db return DbResult; } }
and use this in a foreach:
foreach( object o in Complex ) { ... }
Will the clr call Complex only once, and save a reference to the direct variable actually exposed, or will it execute the code in the get routine each iteration?
Thanks in advance,
Ben Joldersma Sr. Software Engineer, Citadel Media, Inc.
Thanks so much for checking. I should have thought of that! -----Original Message----- Hi Benjamin,
It call it once.
This is VERY easy to check ( I just did it ), just put a
breakpoint insidethe get method , you will see it only enters once.
Cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
"Benjamin Joldersma" <be**@theinsiders.com> wrote in message news:8f**************************@posting.google. com... Hi all,
If I have a expensive public property that exposes a
collection, say via a call to a database:
public ArrayList Complex { get { //expensive call to db return DbResult; } }
and use this in a foreach:
foreach( object o in Complex ) { ... }
Will the clr call Complex only once, and save a
reference to the direct variable actually exposed, or will it execute the
code in the get routine each iteration?
Thanks in advance,
Ben Joldersma Sr. Software Engineer, Citadel Media, Inc.
. -----Original Message----- Benjamin Joldersma <be**@theinsiders.com> wrote:
<snip>
Will the clr call Complex only once, and save a
reference to the direct variable actually exposed, or will it execute the
code in the get routine each iteration? It calls it once, and gets an iterator. So no, you don't
need to worryabout the time it takes to evaluate that.
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too . This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Randell D. |
last post by:
Folks,
Ever since reading an interesting article in Linux Format on PHP whereby
suggested code writing was made that could enhance performance on a...
|
by: Andreas Lauffer |
last post by:
I changed from Access97 to AccessXP and I have immense performance
problems.
Details:
- Access XP MDB with Jet 4.0 ( no ADP-Project )
-...
|
by: joerg |
last post by:
Hello,
we reached a quite interesting performance-limit while using JDBC type
4 to a DB2 V8.1 database. The DB2 is running on a Intel-based single...
|
by: Scott |
last post by:
I have a customer that had developed an Access97 application to track
their business information. The application grew significantly and
they used...
|
by: cody |
last post by:
What about an enhancement of foreach loops which allows a syntax like that:
foeach(int i in 1..10) { } // forward
foeach(int i in 99..2) { } //...
|
by: Tripper |
last post by:
Which is the better way to go and why?
//trivial example
List<string> strings = GetStrings();
foreach (string s in strings)
{
// some...
|
by: Ryan Liu |
last post by:
Hi,
I heard foreach is slower then use loop directly, is that really true?
When loop though a list in a multiple thread environment, is that a...
|
by: jmacduff |
last post by:
I have a performance issue related to regular expressions and
caching , hopefully someone can point me in the right direction?
I have a asp.net...
|
by: jehugaleahsa |
last post by:
I have a rather complex need.
I have a class that parses web pages and extracts all relevant file
addresses. It allows me to download every pdf...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...
| |