473,800 Members | 2,731 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

yield question

I have the following code

ArrayList list = new ArrayList();
foreach (string name in FilesNames())
{
list.Add(name);
}
return list.ToArray();

which basically calls FileNames() method which yeild a string for each
call. It works file. The objective of this method to return an
object[] back so that it can be used to add it into the listview.
Adding the list view also works correct.

My question, is there a better way of doing this?

return FileNames().ToA rray<object>(); ???

I thought it might work but the convertion from IEnumeration to
ICollection doesn't work, what is the best way of doing it?

Thanks.
Apr 4 '08 #1
2 1141
On Apr 4, 11:14*am, CSharper <cshar...@gmx.c omwrote:
I have the following code

ArrayList list = new ArrayList();
foreach (string name in FilesNames())
{
* * *list.Add(name) ;}

return list.ToArray();

which basically calls FileNames() method which yeild a string for each
call. It works file. The objective of this method to return an
object[] back so that it can be used to add it into the listview.
Adding the list view also works correct.

My question, is there a better way of doing this?

return FileNames().ToA rray<object>(); ???

I thought it might work but the convertion from IEnumeration to
ICollection doesn't work, what is the best way of doing it?

Thanks.
Hi,

Did you try binding FilesNames() directly? You are not forced to use
ArrayList
Apr 4 '08 #2
On Apr 4, 3:56*pm, "Ignacio Machin ( .NET/ C# MVP )"
<ignacio.mac... @gmail.comwrote :
On Apr 4, 11:14*am, CSharper <cshar...@gmx.c omwrote:


I have the following code
ArrayList list = new ArrayList();
foreach (string name in FilesNames())
{
* * *list.Add(name) ;}
return list.ToArray();
which basically calls FileNames() method which yeild a string for each
call. It works file. The objective of this method to return an
object[] back so that it can be used to add it into the listview.
Adding the list view also works correct.
My question, is there a better way of doing this?
return FileNames().ToA rray<object>(); ???
I thought it might work but the convertion from IEnumeration to
ICollection doesn't work, what is the best way of doing it?
Thanks.

Hi,

Did you try binding FilesNames() directly? You are not forced to use
ArrayList- Hide quoted text -

- Show quoted text -
Yes I did, but I got it resolved with Jon's approch.
Apr 4 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1496
by: Daniel Brodie | last post by:
Hello, 1) I am trying to understand how yield works in a bytecode way. How exactly does the YIELD_VALUE instruction work? Does the function 'change' to return a generator at compile time (which, from my understanding, not much happens at that stage in python) or at the YIELD_VALUE bytecode? Any pointer to documentation about this would be appriciated, I have tried, but havn't really found anything.
2
8744
by: yyhhjj | last post by:
I created a test program to implement an iterator. First, I used 'yield break' in the iterator, it worked normally. Then, I simply used 'break' in the places of 'yield break', it still worked normally. What's the difference between 'yield break' and 'break' here? Thanks!
2
7383
by: IntraRELY | last post by:
I know this isnt really a VB question per say, but is what I am developing in VB.NET and Excel is the only place that has provided direction. I wanted to ask the public if perhaps you could lend me a hand a point me into the right direction if there is someone who has had experiance with this. By all means if you know a better place to ask, let me know. There is an excel help file titled YIELD. I will copy any paste the file below. I am...
22
2221
by: Mateuszk87 | last post by:
Hi. may someone explain "yield" function, please. how does it actually work and when do you use it? thanks in forward mateusz
3
6941
by: Ehsan | last post by:
hi coulde any one show me the usage of "yield" keyword specially in this example: """Fibonacci sequences using generators This program is part of "Dive Into Python", a free Python book for experienced programmers. Visit http://diveintopython.org/ for the latest version.
6
1533
by: Shriphani | last post by:
Hello all, Let us say I have a function like this: def efficientFiller(file): worthless_list = pot_file = open(file,'r') pot_file_text = pot_file.readlines() for line in pot_file_text: if line.find("msgid") != -1:
1
1079
by: castironpi | last post by:
What if I say oath= yield or other= yield ?
13
1823
by: Martin Sand Christensen | last post by:
Hi! First a bit of context. Yesterday I spent a lot of time debugging the following method in a rather slim database abstraction layer we've developed: ,---- | def selectColumn(self, table, column, where={}, order_by=, group_by=): | """Performs a SQL select query returning a single column
7
1513
by: Alex Bryan | last post by:
Okay, so i don't really understand the Yield thing and i know it is useful. I've read a few things about it but it is all programming jargon and so basically it is hard for me to understand. So can anyone give me a description or link me to a site that has a good definition and/or examples of it? If you could I would really appreciate it.
5
1144
by: defn noob | last post by:
def letters(): a = xrange(ord('a'), ord('z')+1) B = xrange(ord('A'), ord('Z')+1) while True: yield chr(a) yield chr(B) Traceback (most recent call last):
0
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10504
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10251
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10033
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.