By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,198 Members | 1,412 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,198 IT Pros & Developers. It's quick & easy.

loop

P: n/a
Hi, Im using
List<BFEvent> bfe = bf.GetEvents(7);
//do something
for (int i=0; i != bfe.Count; i++);
{
HorseRacing.Items.Add(bfe[0].eventName + " " +
bfe[0].eventId);
}
to get data from array bfe. My problem is if i put i in bfe[i], i get
an error not used in this context. Im getting the correct count. if I
put i there I also get possibly empty ..... in the for...
Any ideas
Regards Robert

May 15 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Ro********@yahoo.co.uk <Ro********@yahoo.co.uk> wrote:
Hi, Im using
List<BFEvent> bfe = bf.GetEvents(7);
//do something
for (int i=0; i != bfe.Count; i++);
{
HorseRacing.Items.Add(bfe[0].eventName + " " +
bfe[0].eventId);
}
to get data from array bfe. My problem is if i put i in bfe[i], i get
an error not used in this context. Im getting the correct count. if I
put i there I also get possibly empty ..... in the for...


What do you mean by "an error not used in this context"? I suspect
that's not the full error message.

I'd generally suggest using a foreach loop instead of the for loop
here, by the way - it doesn't look like you really need to know which
index you're using.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 15 '06 #2

P: n/a
Well, without more detail there's not much there to reproduce it; however,
since you don't use i elsewhere in the loop you could just cut your losses
and use something like below; you might additionally want to check that none
ot the BFEvents returned are null (just in case this is the problem):

foreach(BFEvent theEvent in bfe) {
HorseRacing.Items.Add(theEvent.eventName + " " +
theEvent.eventId);
}
from array bfe


Actually, bfe isn't an array; it is declared as a list; indexers do[th] not
an array make[th]

Marc
May 15 '06 #3

P: n/a
Robert,

Could you pls post the exact text of the error message.
If you can also write a compilable sample code that doesn't use classes from
your app like BFEvent and demonstrates the problem will be of a big help
also.
--

Stoitcho Goutsev (100)

<Ro********@yahoo.co.uk> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com...
Hi, Im using
List<BFEvent> bfe = bf.GetEvents(7);
//do something
for (int i=0; i != bfe.Count; i++);
{
HorseRacing.Items.Add(bfe[0].eventName + " " +
bfe[0].eventId);
}
to get data from array bfe. My problem is if i put i in bfe[i], i get
an error not used in this context. Im getting the correct count. if I
put i there I also get possibly empty ..... in the for...
Any ideas
Regards Robert

May 15 '06 #4

P: n/a
Hi, thankyou for your replys. Im using this with the betfair API to get
a list of events (bf.getevents) and the fill the listbox(horseracing)
with the name and event ids. Marc your suggestion foreach(BFEvent
theEvent in bfe) {
HorseRacing.Items.Add(theEvent.eventName + " " +
theEvent.eventId); has solved this, and fills the lisbox perfect.
Am I correct in thinking that this looks at each event 1 at a time,
adding the data to theevent then added elements to the list, then moves
to the next. Sorry for what is probably simple. Because Im new to
programming Im trying to make sure I understand each process I add to
my program.
Thanks again Regards Robert

May 15 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.