473,327 Members | 2,012 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,327 software developers and data experts.

Generic List to Array

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

May 25 '07 #1
2 2991
SAL
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

"shapper" <md*****@gmail.comwrote in message
news:11*********************@m36g2000hse.googlegro ups.com...
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

May 25 '07 #2
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
May 25 '07 #3

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

Similar topics

8
by: JAL | last post by:
Here is my first attempt at a deterministic collection using Generics, apologies for C#. I will try to convert to C++/cli. using System; using System.Collections.Generic; using System.Text; ...
11
by: ZenRhapsody | last post by:
Has anyone done any performance testing between new generic Lists and single dimensional arrays? I really like the code flexibility the List provides since I don't know how many items I will...
6
by: Lee Crabtree | last post by:
Pinning a regular managed array is pretty easy in C++/CLI, such as: if buffer is defined thusly: array<System::Byte^buffer pinning it would be something like: pin_ptr<unsigned charpinBuf =...
6
by: Jeff.Boeker | last post by:
I'm learning a lesson in how I need to be more specific :) In C++ I can resize a vector and it will allocate memory and it will call the default constructor if necessary (or I can supply an...
6
by: Nick Valeontis | last post by:
I know how to use Icomparable. However, I can't figure out how to sort a generic linked list? (without writing the algorithm) Lets say I have something like this: class...
4
by: =?Utf-8?B?QkogU2FmZGll?= | last post by:
We have a class that has a public property that is of type List<T>. FXCop generates a DoNotExposeGenericLists error, indicating "System.Collections.Generic.List<Tis a generic collection designed...
1
by: Miesha.James | last post by:
Hello, I'm trying to rewrite visual c++ code into visual c++ .NET code and I've run across a problem with storing objects into a list. Here;s an example of the code I have: ref struct...
2
by: Chris Kennedy | last post by:
I am getting a generic list of objects from a webservice. The list is converted to an array by this process. How do I convert the array back to a list and is there any way of finding an object...
2
by: SimonDotException | last post by:
I am trying to use reflection in a property of a base type to inspect the properties of an instance of a type which is derived from that base type, when the properties can themselves be instances of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.