Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 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 Professional 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 April 28th, 2007, 04:28 AM
Authorized User
 
Join Date: Aug 2006
Location: , , .
Posts: 39
Thanks: 1
Thanked 0 Times in 0 Posts
Default Convert 'string' to 'string[]'

Hello,

1. I have an array as

string[] arr = new string[24];

2. After populating it stored in a session variable as

Session["Response"] = arr;

3. On the next page, I want to reconvert session variable to array as

string[] arr = new string[24];
arr = Convert.ToString(Session["Response"]) ;

4. Giving error message as

Cannot implicitly convert type 'string' to 'string[]'

Please tell me what to do.

 
Old April 29th, 2007, 08:54 PM
Authorized User
 
Join Date: Mar 2006
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You are doing a mistake in step 3. You are converting session value to string and assigning it to an array. It will definitely fail.

Change the Step 3 like this:

    string[] arr = (string[]) Session["Response"];

Make sure you check the 'arr' for null or 0 length before using for the first time after this assignment. There is a potential for NullReferenceException if it is used without checking.


Cheers,
Sai Puli

 
Old May 1st, 2007, 04:11 AM
Authorized User
 
Join Date: Aug 2006
Location: , , .
Posts: 39
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Oh, I got it. Thanks a lot it is working fine.





Similar Threads
Thread Thread Starter Forum Replies Last Post
convert string to function austinf Javascript 3 September 19th, 2008 03:25 AM
convert to string prafullaborade XML 7 May 29th, 2008 02:59 PM
Convert a string into a variable jtrifts VBScript 4 February 21st, 2008 09:08 AM
Convert DBNull to String GailCG ASP.NET 2.0 Basics 1 November 21st, 2006 02:16 AM
convert string to integer kcheung Classic ASP Databases 1 July 28th, 2003 04:39 PM





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