Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0How to convert a list of objects to an ArrayList?How to convert a list of objects to an ArrayList?
Previous
 
Next
New Post
7/9/2007 7:38 PM
 

I am struggling... Please help me if you can. Thanks

I have the following....

In my Controller I have..

Public Function GetRacesByMonth(ByVal schDate As Date, ByVal ModuleId As Integer) As List(Of RacesInfo)
Return CBO.FillCollection(Of RacesInfo)(DataProvider.Instance().GetRacesByMonth(schDate, ModuleId))
End Function

In my ascx.vb code I have

Dim Arr As New System.Collections.ArrayList
Arr = x.GetRacesByMonth(e.Day.Date, ModuleId)

The error is: Value of type 'System.Collections.Generic.List(Of FWM.Modules.Races.RacesInfo)' cannot be converted to 'System.Collections.ArrayList'.

I really need it in an ArrayList how do I cast it or convert it?

 
New Post
7/10/2007 5:12 AM
 

I don't know if you are aware , but a generic list is really - an ArrayList underneath :). It just uses generics but it's still an array list .

 

But if you really want to convert , you could do a foreach on the values returned by x.GetRacesByMonth(e.Day.Date, ModuleId) and add them one by one to the array list.

I however don't see the need for this.

 
New Post
7/10/2007 3:25 PM
 

I really did not realize that.... Thanks for your help and everything works great now.

 

 
New Post
7/10/2007 3:44 PM
 

Like rollerblade said, there really shouldn't be any reason that you'd need to convert a generic List to an ArrayList unless you're having to pass it to a function that you don't control which requires an ArrayList.

If you really need to convert, the best method is probably as follows:

Dim arr as List(Of RaceInfo) = x.GetRacesByMonth(e.Day.Date, ModuleId)
Dim arrList as New System.Collections.ArrayList(arr)

The ArrayList constructor will take a parameter of type ICollection, so you can just send it your generic list.


Brian Dukes
Engage Software
St. Louis, MO
866-907-4002
DNN partner specializing in custom, enterprise DNN development.
 
New Post
7/11/2007 10:01 AM
 

I too just wanted to chime in on this one.  I would also recommend leaving this as a generic list.  The generic list provides type safe methods to access the individual items and prevents runtime errors due to accessing memebers that may or may not be there.  I think it makes easier to read code as well...

just my $0.02


-Mitchel Sellers
Microsoft MVP, ASPInsider, DNN MVP
CEO/Director of Development - IowaComputerGurus Inc.
LinkedIn Profile

Visit mitchelsellers.com for my mostly DNN Blog and support forum.

Visit IowaComputerGurus.com for free DNN Modules, DNN Performance Tips, DNN Consulting Quotes, and DNN Technical Support Services
 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0How to convert a list of objects to an ArrayList?How to convert a list of objects to an ArrayList?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out