473,652 Members | 3,059 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ArrayList.GetEn umerator(x,y) --- how to use?

ArrayList implements an overload for IEnumerator's GetEnumerator method
as follows:

GetEnumerator(i nt offset, int count)

However, I can't see a way to take advantage of this, even though I'd
like to... I'd like to be able to use foreach to iterate over a section
of the ArrayList, but can't find any syntax that will work. The obvious:

foreach char ch in arList(0,20)
{
....
}

does not compile at all. Any ideas? Is this only usable if you actually
want the IEnumerator interface for something else besides foreach?
Nov 16 '05 #1
1 4913
> ArrayList implements an overload for IEnumerator's GetEnumerator method
as follows:

GetEnumerator(i nt offset, int count)

However, I can't see a way to take advantage of this, even though I'd
like to... I'd like to be able to use foreach to iterate over a section
of the ArrayList, but can't find any syntax that will work. The obvious:

foreach char ch in arList(0,20)
{
...
}

does not compile at all. Any ideas? Is this only usable if you actually
want the IEnumerator interface for something else besides foreach?


It would be great if C# would support such a syntax.
No You have to go the verbose way:

Enumerator e = array.GetEnumer ator(0,20);
while(e.MoveNex t())
{
Console.WriteLi ne(e.Current);
}

but for usage with ArrayList thats plain stupid and slow, better would be
here a normal for loop.
--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
Nov 16 '05 #2

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

Similar topics

3
1889
by: george r smith | last post by:
I am trying to create an arrayList that contains multiple arrayLists. My code attempt is below. The question I have is how can I get away from creating another pAttribute list than can be added to pItem. As I understand it (and I coded it to test) if I try to use pAttribute again by clearing with pAttribute.Clear because it is a shallow copy the pItem is also cleared. I guess I need a "deep copy" but can't find any documentation on it. ...
1
2485
by: Matthias S. | last post by:
Hi, I'm trying to provide the user of my class access to the objects in a collection without allowing him to modify (add/remove/clear items) the collection. I thought I can do it by providing a IEnumerator. But this thingy can't be used directly, as shown in the code below. How can this be done? Thanks in advance.
9
5084
by: vbportal | last post by:
Hi, I would like to add BitArrays to an ArrayList and then remove any duplicates - can someone please help me forward. I seem to have (at leaset ;-) )2 problems/lack of understanding (see test code below): (a)When adding BitArrays to the ArrayList and then looping through the ArrayList I seem to access only the latest added BitArray and I'm not exactly clear on best way to access each BItArray in the ArrayList (b)When I try to remove...
2
5066
by: Rob G | last post by:
Hello, I have a basic understanding of Objects, inheritance, polymorhpism, etc. I am new to VB.NET and I am having a problem figuring this out. I want to sort a CheckBoxList. Using the ArrayList seemed to make the most sense. When I use it I get the error: At least one object must implement IComparable. Here's the code that produces that error: Public Class Sorting
20
5967
by: Dennis | last post by:
I use the following code for a strongly typed arraylist and it works great. However, I was wondering if this is the proper way to do it. I realize that if I want to implement sorting of the arraylist then I have to handle this with a sort method that uses comparer. I can reference the properties of the Arraylist directly such as dim mylist as new FrameList mylist.Add(new FrameStructure) mylist(0).first = "blabla..." mylist(0).second...
1
1736
by: Joe | last post by:
Hello All: I am writing a function which accepts an ArrayList as its parameter and converts the contents of the ArrayList into an XmlNodeList. The ArrayList will contain one of several different structures. For example, the structures could be either a Customer structure (which contains a customer id and name) or an Address structure (which contains an address type and street number, city, etc). The XmlNodeList is uded to populate a...
3
4323
by: starter | last post by:
I am trying to learn IEnumerator and collections(ArrayList, Hashtable) in .NET. Can anyone tell me what is IEnumerator used for and any online resources would be helpful. Thanks
31
4578
by: Extremest | last post by:
I have a loop that is set to run as long as the arraylist is > 0. at the beginning of this loop I grab the first object and then remove it. I then go into another loop that checks to see if there are more objects that match the first object that i grabbed. If they match then I put them in an array. I would like to remove each match from the arraylist as I find them to speed things up and so that they don't get checked again. If I try...
6
2794
by: Vinit | last post by:
Hi I am passing an arraylist to a c#/.net webmethod from a perl client using soap:lite. The trace shows the elements in the xml request. The arraylist input in the webmethod however does not contain any values and is empty. It works fine with arrays....but NOT arraylists....does anyone know WHY? and HOW TO SOLVE THIS ISSUE? Regards,
0
8367
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
8703
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8467
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
8589
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
5619
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4145
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2703
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1591
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.