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 1693
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 server,
I've started testing various bits of...
|
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 )
- Linked Tables to SQL-Server 2000 over ODBC
I used...
|
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
CPU-Server with Linux OS.
What we are doing is...
|
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 the Upsizing Wizard to move the tables to SQL...
|
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) { } // backwards
foeach(char c in 'a'..'z') { } // chars...
|
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 operation;
}
strings.ForEach(
|
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 good
practice to copy this list to an array the...
|
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 web service that is called several million times a...
|
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 on a web page, for
instance. I would like to...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |