locked
Adding iList element RRS feed

  • Question

  • User31164289 posted

    I have this code:

    Dim MedicList As IList(Of Medic)


    I want to add item in List. When I write this code

    MedicList.Add(New Medic)
    Visual studio say "MedicList is used before assigned value to it"
    How I can do it?
    How I can insert properties value for class:
    Medic.Name ="Peter"
    Medic.Age ="34"
    Etc...




    Friday, December 17, 2010 3:00 PM

Answers

  • User1006193418 posted

    I cannot use List insetad iList because I'm calling a webservces that don't accept it.

    Hi,

    Have you tried on ArrayList?

            Dim MedicList As New ArrayList
            MedicList.Add(New Medic)

    And could you explain a bit more why you cannot use List(T)? It doesn't make sense as iList(T) and List(T) are in the same namespace System.Collections.Generic.

    Best Regards,
    Shengqing Yang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 22, 2010 10:21 PM

All replies

  • User197322208 posted

    Dim MedicList As IList(Of Medic)  = new List(Of Medic)

    Friday, December 17, 2010 3:21 PM
  • User31164289 posted

    Don't work.

    InvalidCastException..

    Friday, December 17, 2010 3:30 PM
  • User197322208 posted

    on what line ?

    the  List(Of T) _

    	Implements IList(Of T)

    http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx
    Friday, December 17, 2010 3:40 PM
  • User31164289 posted

    This Line


    Dim MedicList As IList(Of Medic)  = new List(Of Medic)

    Friday, December 17, 2010 4:03 PM
  • User197322208 posted

    let's suppose you are right

    how about

    Dim MedicList as new List(Of Medic)

    Friday, December 17, 2010 5:17 PM
  • User31164289 posted

    I cannot use List insetad iList because I'm calling a webservces that don't accept it.

    Saturday, December 18, 2010 1:08 AM
  • User31164289 posted

    Cannout use List of T insetad iList

    Saturday, December 18, 2010 1:30 AM
  • User1006193418 posted

    I cannot use List insetad iList because I'm calling a webservces that don't accept it.

    Hi,

    Have you tried on ArrayList?

            Dim MedicList As New ArrayList
            MedicList.Add(New Medic)

    And could you explain a bit more why you cannot use List(T)? It doesn't make sense as iList(T) and List(T) are in the same namespace System.Collections.Generic.

    Best Regards,
    Shengqing Yang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 22, 2010 10:21 PM