Click here to Skip to main content
15,886,788 members
Home / Discussions / Visual Basic
   

Visual Basic

 
Questionvb.net 2010 sum value in a collectionh Pin
dcof16-Apr-15 11:48
dcof16-Apr-15 11:48 
AnswerRe: vb.net 2010 sum value in a collectionh Pin
Sascha Lefèvre16-Apr-15 12:27
professionalSascha Lefèvre16-Apr-15 12:27 
GeneralRe: vb.net 2010 sum value in a collectionh Pin
dcof17-Apr-15 4:17
dcof17-Apr-15 4:17 
GeneralRe: vb.net 2010 sum value in a collectionh Pin
Sascha Lefèvre17-Apr-15 6:07
professionalSascha Lefèvre17-Apr-15 6:07 
QuestionCreate a list of Unknown type at compile time Pin
dilkonika16-Apr-15 10:58
dilkonika16-Apr-15 10:58 
AnswerRe: Create a list of Unknown type at compile time Pin
Sascha Lefèvre16-Apr-15 11:02
professionalSascha Lefèvre16-Apr-15 11:02 
GeneralRe: Create a list of Unknown type at compile time Pin
dilkonika16-Apr-15 11:53
dilkonika16-Apr-15 11:53 
GeneralRe: Create a list of Unknown type at compile time Pin
Sascha Lefèvre16-Apr-15 12:15
professionalSascha Lefèvre16-Apr-15 12:15 
This works for me:
VB
Option Explicit On
Option Strict On

Imports System.Reflection

Module Module1

    Public Class ChildClass
    End Class

    Public Class SomeClass
        Public Property Children As ICollection(Of ChildClass) = New HashSet(Of ChildClass)
    End Class

    Sub Main()
        Dim tempType = GetType(ChildClass)
        Dim someClass = New SomeClass
        someClass.Children.Add(New ChildClass)

        Dim customList As Type = GetType(List(Of )).MakeGenericType(tempType)
        Dim objectList As IList = CType(Activator.CreateInstance(customList), IList)

        ' Copy items from a PropertyInfo list to the object just created
        Dim o As Object = someClass
        Dim p As PropertyInfo = o.[GetType]().GetProperty("Children")
        Dim copyFrom As IEnumerable = CType(p.GetValue(o, Nothing), IEnumerable)
        For Each item As Object In copyFrom
            objectList.Add(item)
        Next
        ' Will throw exceptions if the types don't match.
        ' Iterate and access the items of "objectList"
        ' (objectList declared above as non-generic IEnumerable)
        For Each item As Object In objectList
            Debug.WriteLine(item.ToString())
        Next
    End Sub

End Module

If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

GeneralRe: Create a list of Unknown type at compile time Pin
dilkonika16-Apr-15 13:05
dilkonika16-Apr-15 13:05 
GeneralRe: Create a list of Unknown type at compile time Pin
Sascha Lefèvre16-Apr-15 13:14
professionalSascha Lefèvre16-Apr-15 13:14 
GeneralRe: Create a list of Unknown type at compile time Pin
dilkonika16-Apr-15 13:51
dilkonika16-Apr-15 13:51 
GeneralRe: Create a list of Unknown type at compile time Pin
Sascha Lefèvre16-Apr-15 14:18
professionalSascha Lefèvre16-Apr-15 14:18 
GeneralRe: Create a list of Unknown type at compile time Pin
dilkonika16-Apr-15 14:23
dilkonika16-Apr-15 14:23 
GeneralRe: Create a list of Unknown type at compile time Pin
Sascha Lefèvre16-Apr-15 14:39
professionalSascha Lefèvre16-Apr-15 14:39 
GeneralRe: Create a list of Unknown type at compile time Pin
dilkonika16-Apr-15 16:03
dilkonika16-Apr-15 16:03 
GeneralRe: Create a list of Unknown type at compile time Pin
Sascha Lefèvre17-Apr-15 2:53
professionalSascha Lefèvre17-Apr-15 2:53 
QuestionExtended ASCII with UTF-8 in VB.NET Pin
r_m_radha15-Apr-15 2:28
r_m_radha15-Apr-15 2:28 
AnswerRe: Extended ASCII with UTF-8 in VB.NET Pin
Richard MacCutchan15-Apr-15 2:41
mveRichard MacCutchan15-Apr-15 2:41 
GeneralRe: Extended ASCII with UTF-8 in VB.NET Pin
r_m_radha15-Apr-15 17:44
r_m_radha15-Apr-15 17:44 
GeneralRe: Extended ASCII with UTF-8 in VB.NET Pin
Richard MacCutchan15-Apr-15 21:30
mveRichard MacCutchan15-Apr-15 21:30 
QuestionHashSet(Of T) - how can I get elements by position number ? Pin
dilkonika14-Apr-15 12:20
dilkonika14-Apr-15 12:20 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
PIEBALDconsult14-Apr-15 12:55
mvePIEBALDconsult14-Apr-15 12:55 
AnswerRe: HashSet(Of T) - how can I get elements by position number ? Pin
Sascha Lefèvre14-Apr-15 13:23
professionalSascha Lefèvre14-Apr-15 13:23 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
dilkonika14-Apr-15 16:42
dilkonika14-Apr-15 16:42 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
Sascha Lefèvre14-Apr-15 22:57
professionalSascha Lefèvre14-Apr-15 22: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.