PC Review


Reply
Thread Tools Rate Thread

can i know how many item in ENUM )in run time) ?

 
 
Daylor
Guest
Posts: n/a
 
      24th Jul 2003
Public Enum COLORS

RED= 0

GREEN=1

BLUD =2

ORANGE =4

End Enum


public sub FooWithColors(enmColor as COLORS )
//here , i want to able to know this in run time :
//1.many colors i have in the enum ? (4)
//2.what is the value for each color (0,1,2,4)

end sub

how can i do that in vb.net ?

thanks and have a nice day.


 
Reply With Quote
 
 
 
 
Jeff Levinson [mcsd]
Guest
Posts: n/a
 
      24th Jul 2003
Use this code (it's a console app):

Module Module1

Public Enum MyColors
RED = 0
GREEN = 1
BLUD = 2
ORANGE = 4
End Enum

Sub Main()
Dim i As Integer = [Enum].GetValues(GetType
(MyColors)).Length
Console.WriteLine("Number of values = {0}",
i.ToString)

For j As Integer = 0 To i - 1
Console.WriteLine("{0} - {1}", [Enum].GetNames
(GetType(MyColors)).GetValue(j), _
Convert.ToInt32([Enum].GetValues(GetType
(MyColors)).GetValue(j)))
Next

Console.ReadLine()
End Sub

End Module

Jeff Levinson

Author of "Building Client/Server Applications with
VB.NET: An Example Driven Approach"

>-----Original Message-----
>Public Enum COLORS
>
>RED= 0
>
>GREEN=1
>
>BLUD =2
>
>ORANGE =4
>
>End Enum
>
>
>public sub FooWithColors(enmColor as COLORS )
>//here , i want to able to know this in run time :
>//1.many colors i have in the enum ? (4)
>//2.what is the value for each color (0,1,2,4)
>
>end sub
>
>how can i do that in vb.net ?
>
>thanks and have a nice day.
>
>
>.
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Handle different international time zones for Item.Start and Item. masani paresh Microsoft Outlook VBA Programming 14 6th Aug 2008 05:27 AM
How to I get number of item in an enum tony Microsoft C# .NET 3 28th Mar 2006 02:51 PM
Re: enum item from string Herfried K. Wagner [MVP] Microsoft VB .NET 0 13th Apr 2005 10:25 PM
Re: enum item from string Peter Lillevold Microsoft VB .NET 0 13th Apr 2005 09:51 PM
Re: enum item from string Tom Shelton Microsoft VB .NET 0 13th Apr 2005 09:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:55 PM.