Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. type cast in vb.net

type cast in vb.net

Scheduled Pinned Locked Moved Visual Basic
csharpcom
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rprateek
    wrote on last edited by
    #1

    I have one arraylist where i load up all bookinfo obj and want to return the collection of bookinfo[] I can do it the following way in c# but I need to know how can we type cast the following in vb.net: ArrayList a=new ArrayList(); Bookinfo obj=new BookInfo(); return (BookInfo[])a.ToArray(obj.GetType());

    Blog for Programmers

    S G 2 Replies Last reply
    0
    • R rprateek

      I have one arraylist where i load up all bookinfo obj and want to return the collection of bookinfo[] I can do it the following way in c# but I need to know how can we type cast the following in vb.net: ArrayList a=new ArrayList(); Bookinfo obj=new BookInfo(); return (BookInfo[])a.ToArray(obj.GetType());

      Blog for Programmers

      S Offline
      S Offline
      Steven J Jowett
      wrote on last edited by
      #2

      I think thi will do it :-

      Dim a As New ArrayList()
      Dim obj As Bookinfo = New BookInfo()

      Return DirectCast(a.ToArray(obj.[GetType]()), BookInfo())

      Steve Jowett ------------------------- Real programmers don't comment their code. If it was hard to write, it should be hard to read.

      R 1 Reply Last reply
      0
      • S Steven J Jowett

        I think thi will do it :-

        Dim a As New ArrayList()
        Dim obj As Bookinfo = New BookInfo()

        Return DirectCast(a.ToArray(obj.[GetType]()), BookInfo())

        Steve Jowett ------------------------- Real programmers don't comment their code. If it was hard to write, it should be hard to read.

        R Offline
        R Offline
        rprateek
        wrote on last edited by
        #3

        thanks steve

        Blog for Programmers

        1 Reply Last reply
        0
        • R rprateek

          I have one arraylist where i load up all bookinfo obj and want to return the collection of bookinfo[] I can do it the following way in c# but I need to know how can we type cast the following in vb.net: ArrayList a=new ArrayList(); Bookinfo obj=new BookInfo(); return (BookInfo[])a.ToArray(obj.GetType());

          Blog for Programmers

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          Unless you are stuck with framework 1, don't use ArrayList at all. Use a generic list. As it's strongly typed you don't need any casting: List<Bookinfo> a = new List<Bookinfo>(); Bookinfo b = new Bookinfo(); a.Add(b); return a.ToArray();

          Despite everything, the person most likely to be fooling you next is yourself.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups