Click here to Skip to main content
15,909,939 members
Home / Discussions / C#
   

C#

 
QuestionGet const-collection from code? Pin
Ariadne21-Apr-09 4:29
Ariadne21-Apr-09 4:29 
AnswerRe: Get const-collection from code? Pin
DaveyM6921-Apr-09 4:49
professionalDaveyM6921-Apr-09 4:49 
GeneralRe: Get const-collection from code? Pin
OriginalGriff21-Apr-09 4:54
mveOriginalGriff21-Apr-09 4:54 
GeneralRe: Get const-collection from code? Pin
Pete O'Hanlon21-Apr-09 4:57
mvePete O'Hanlon21-Apr-09 4:57 
GeneralRe: Get const-collection from code? Pin
OriginalGriff21-Apr-09 5:07
mveOriginalGriff21-Apr-09 5:07 
AnswerRe: Get const-collection from code? Pin
Pete O'Hanlon21-Apr-09 4:56
mvePete O'Hanlon21-Apr-09 4:56 
GeneralRe: Get const-collection from code? Pin
Ariadne22-Apr-09 2:02
Ariadne22-Apr-09 2:02 
AnswerRe: Get const-collection from code? Pin
Rolando CC21-Apr-09 5:30
professionalRolando CC21-Apr-09 5:30 
HI,

I'm not sure if exist something like ConstantCollection, but this works for me (VB.net):

Firts a simple class:

Public Class Class1
    Public Const c1 As String = "c1"
    Public Const c2 As String = "c2"
    Const c3 As String = "c3"
    Dim var1 As String
    Public var2 As String

    Public Enum myEnum
        value1
        value2
    End Enum

End Class



For Each field As FieldInfo In getConstants(GetType(Class1))
            Console.WriteLine(field.Name)
Next

Private Function getConstants(ByVal pType As System.Type) As List(Of System.Reflection.FieldInfo)
        Dim fis() As FieldInfo
        Dim result As New List(Of System.Reflection.FieldInfo)

        fis = pType.GetFields()

        For Each fi As FieldInfo In fis
            If fi.IsLiteral And Not fi.IsInitOnly Then
                result.Add(fi)
            End If
        Next

        Return result

    End Function


This returns:
c1
c2

The constants must be declared public.

RolCr.
QuestionAccessing File from Remote PC Pin
satsumatable21-Apr-09 4:21
satsumatable21-Apr-09 4:21 
AnswerRe: Accessing File from Remote PC Pin
Rolando CC21-Apr-09 5:39
professionalRolando CC21-Apr-09 5:39 
Questionthe best way to draw a calendar in C# Pin
student198821-Apr-09 4:10
student198821-Apr-09 4:10 
AnswerRe: the best way to draw a calendar in C# Pin
Rob Philpott21-Apr-09 4:44
Rob Philpott21-Apr-09 4:44 
GeneralRe: the best way to draw a calendar in C# Pin
student198821-Apr-09 5:20
student198821-Apr-09 5:20 
GeneralRe: the best way to draw a calendar in C# Pin
musefan21-Apr-09 5:54
musefan21-Apr-09 5:54 
GeneralRe: the best way to draw a calendar in C# Pin
Rob Philpott21-Apr-09 6:00
Rob Philpott21-Apr-09 6:00 
GeneralRe: the best way to draw a calendar in C# Pin
student198821-Apr-09 11:05
student198821-Apr-09 11:05 
GeneralRe: the best way to draw a calendar in C# Pin
22over721-Apr-09 11:41
22over721-Apr-09 11:41 
Questionlistbox string text unorganized Pin
neodeaths21-Apr-09 4:05
neodeaths21-Apr-09 4:05 
AnswerRe: listbox string text unorganized Pin
Eddy Vluggen21-Apr-09 4:31
professionalEddy Vluggen21-Apr-09 4:31 
QuestionSquare Wave using C# Pin
spalanivel21-Apr-09 3:46
spalanivel21-Apr-09 3:46 
AnswerRe: Square Wave using C# Pin
Rob Philpott21-Apr-09 3:49
Rob Philpott21-Apr-09 3:49 
GeneralRe: Square Wave using C# Pin
spalanivel21-Apr-09 4:00
spalanivel21-Apr-09 4:00 
GeneralRe: Square Wave using C# Pin
Rob Philpott21-Apr-09 4:40
Rob Philpott21-Apr-09 4:40 
GeneralRe: Square Wave using C# Pin
spalanivel21-Apr-09 19:38
spalanivel21-Apr-09 19:38 
AnswerRe: Square Wave using C# Pin
Wes Aday21-Apr-09 3:57
professionalWes Aday21-Apr-09 3:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.