Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 13th, 2008, 08:46 AM
Authorized User
 
Join Date: Jan 2008
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default Typecasting for arrayList

Hi
I am trying to retrieve the value at index 0 of an arraylist as string But keep getting the error message "Conversion from type 'BlogInfo' to type 'String' is not valid." . Please help me out...



dim list as new Arraylist
dim Tempstr as string

Dim m_oBlog As New BlogInfo ---> Dotnetnuke.modules.blog.business.BlogInfo
.......
.......
.......
.......

list.Add(m_oBlog)
TempStr = Convert.ToString(list.Item(0))


There are items in the list, so the list is defenitely not empty....


Many Thanks

Sheraz
 
Old February 13th, 2008, 09:29 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Isn't this error somewhat obvious? Position 0 in your array is not of Type string, it is of type BlogInfo which is why your conversion fails.

I am not that familiar with DNN but you should be able to do this:
Dim TempStr as BlogInfo = CType(list.Item(0), BlogInfo)

You can then access the BlogInfo object from the array in this manner:
TempStr.SomeMethod()

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old February 13th, 2008, 10:48 AM
Authorized User
 
Join Date: Jan 2008
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks buddy its working now..

 
Old February 13th, 2008, 11:45 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

No problem, glad it worked out for you. =]

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old February 13th, 2008, 01:13 PM
Authorized User
 
Join Date: Sep 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you like you create your own strongly typed list class by deriving CollectionBase class and implementing your own Add/Remove/Insert/WhatEver methods. See example here: http://msdn2.microsoft.com/en-us/lib...ctionbase.aspx

 
Old February 13th, 2008, 03:16 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Or even easier, just use a generic list for your desired type.

-Peter
 
Old February 13th, 2008, 03:48 PM
Authorized User
 
Join Date: Sep 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ah. Stupid me. This was ASP.NET 2 discussion :)





Similar Threads
Thread Thread Starter Forum Replies Last Post
ArrayList Mogg-Way C# 2005 5 February 12th, 2008 04:05 PM
SiteIdentity TypeCasting Problem RM82 BOOK: ASP.NET Website Programming Problem-Design-Solution 3 September 17th, 2005 10:38 AM
Help with an arraylist crazy-nun General .NET 4 July 14th, 2005 03:32 AM
typecasting int to java.lang.Integer ruchilalla J2EE 1 May 23rd, 2005 06:11 AM
ArrayList kobystud C# 4 May 25th, 2004 02:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.