Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / May 2007

Tip: Looking for answers? Try searching our database.

Generic List to Array

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
shapper - 25 May 2007 12:13 GMT
Hello,

I have a generic list as follows:
Dim categories As Generic.List(Of Enumeration.Category)

Category is an enumeration as follows:

   Public Enum Category
     Book
     Document
     Paper
   End Enum

How can I convert categories to a string array which would become
something as follows:
Book,Document,Paper, ...

I tried:
categories.ToArray

And I get the error:
Value of type '1-dimensional array of Category' cannot be converted to
'1-dimensional array of String'

Thanks,
Miguel
SAL - 25 May 2007 17:11 GMT
What you could do is inherit from Generic.List (type safe) and then add a
ConvertToStringArray method and do the work of converting it to an array of
string arrays..

Just a thought

S

> Hello,
>
[quoted text clipped - 22 lines]
> Thanks,
> Miguel
CharlesA - 25 May 2007 17:24 GMT
Shapper

this is much easier
Class enumsExample
 
 Public Shared Sub Main()    
   For Each value As String In [Enum].GetNames(GetType(Category))
   'just show the value in the console window for now    
     Console.WriteLine(value)
   Next value
 End Sub
End Class

and if you want to place it in an array you create the array before hand and
stuff each 'value' into the right cubby-hole in the array, or even adding it
to a ArrayList and use ToArray on that...

There is a also a GetValues for getting at the underlying Integer values
Shared method of the [Enum] class (has to be in square brackets in VB as it's
a reserved word as well as a class name)
I hope this helps
Cheers
CharlesA

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.