type cast in vb.net
-
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());
-
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());
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.
-
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.
thanks steve
-
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());
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.