473,394 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

New to .NET - ArrayList Question

I have an ArrayList of DirectoryInfo structures. As I'm certain you know,
each DirectoryInfo structure has a property called FullName. I'm trying to
get at the fullname property for the first element in the array so I can
assign it to a var but I can't seem to figure out how to do it.

Image.FromFile(alDirInfo(0).Item)

Nothing I do reveals this property in the IDE to select. So do I have to use
the CopyTo method of the ArrayList to get at the FullName property? It seems
like I should be able to access each DirectoryInfo structure from right
inside the array. Is this not possible?

Thanks!

JW
Jul 21 '07 #1
3 1392

"Jerry West" <jw@comcast.netha scritto nel messaggio
news:13*************@news.supernews.com...
>I have an ArrayList of DirectoryInfo structures. As I'm certain you know,
each DirectoryInfo structure has a property called FullName. I'm trying to
get at the fullname property for the first element in the array so I can
assign it to a var but I can't seem to figure out how to do it.

Image.FromFile(alDirInfo(0).Item)

Nothing I do reveals this property in the IDE to select. So do I have to
use the CopyTo method of the ArrayList to get at the FullName property? It
seems like I should be able to access each DirectoryInfo structure from
right inside the array. Is this not possible?
Replace ArrayList with List(Of DirectoryInfo)

and obviously

Image.FromFile(alDirInfo.Item(0).FullName)

--
Help The New .Net Site! http://www.devbox4.net
Jul 21 '07 #2
Jerry West wrote:
I have an ArrayList of DirectoryInfo structures. As I'm certain you know,
each DirectoryInfo structure has a property called FullName. I'm trying to
get at the fullname property for the first element in the array so I can
assign it to a var but I can't seem to figure out how to do it.

Image.FromFile(alDirInfo(0).Item)

Nothing I do reveals this property in the IDE to select. So do I have to use
the CopyTo method of the ArrayList to get at the FullName property? It seems
like I should be able to access each DirectoryInfo structure from right
inside the array. Is this not possible?

Thanks!

JW
If you use framework 2.0, use the generic List instead of ArrayList (as
Fabio suggested).

If you use framework 1.x, there is no generics, so you are stuck with
the ArrayList.

The ArrayList is a list of Object, so when you access an item in the
list, you get a reference to Object. You have to cast this reference to
the actual type of the object that you stored in the list to be able to
get to it's properties.

--
Göran Andersson
_____
http://www.guffa.com
Jul 21 '07 #3
Jerry West wrote:
I have an ArrayList of DirectoryInfo structures.
I'm trying to get at the fullname property for the first element
in the array so I can assign it to a var but I can't seem to figure
out how to do it.
The Items of an ArrayList are typed "As Object", because they can be
absolutely any type you can imagine. To get the Object "back" to the
DirectoryInfo object you put in there, you have to "down-cast" each item
to the correct Type (checking first, if there's any doubt), as in

Dim o as Object = alDirInfo(0).Item
Dim s As String = String.Empty

If Typeof( o ) Is DirectoryInfo Then
s = DirectCast( o, DirectoryInfo ).FullName
End If

HTH,
Phill W.
Jul 24 '07 #4

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

Similar topics

7
by: Alex Ting | last post by:
Hi Everybody, I have an issue about deleting an object from an arrayList. I've bounded a datagrid using this code where it will first run through all of the code in loadQuestions() and bind a...
3
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...
10
by: C Downey | last post by:
Hello: I have an arraylist storing some very basic objects. The object is very basic, it has 2 properties : ID, and COUNT Before I add an object to the arraylist, I want to check if an...
6
by: GrandpaB | last post by:
While writing this plea for help, I think I solved my dilemma, but I don't know why the problem solving statement is necessary. The inspiration for the statement came from an undocumented VB...
18
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the...
3
by: Mark Jones | last post by:
I am quite new to ASP and .Net development and I am building a web-based multiple choice exam application. The web page displays the questions using a Repeater control and the answers are nested...
11
by: Simon Says | last post by:
Hi all, I've an arraylist A1 that contains {0,1,2,3,4,5,9,8,7} I've another arraylist A2 that contains {4,5,9} I would like to search whether if A2 is present in A1 and maybe return the first...
6
by: fniles | last post by:
I am using VB.NET 2003 and a socket control to receive and sending data to clients. As I receive data in 1 thread, I put it into an arraylist, and then I remove the data from arraylist and send it...
3
by: Christopher H | last post by:
I've been reading about how C# passes ArrayLists as reference and Structs as value, but I still can't get my program to work like I want it to. Simple example: ...
1
by: =?Utf-8?B?SkI=?= | last post by:
Hello My pgm1 (User Interface Level) passes an empty ArrayList to pgm2 (Business Logic Level). pgm2 then calls pgm3 (Data Access Level) to populate the ArrayList. Question1: When pgm2 gets...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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...
0
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,...
0
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...
0
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...

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.