More Group Sites
School Rankings
Jobless Net
Better Home
Enviro++


Help | Subscribe/Unsubscribe | Rules | Other Group Sites: Better Education | Better Education Forum
Welcome Guest Search | Active Topics | Members | Log In | Register

How to convert integer array to string array Options · View
hong
Posted: Monday, March 28, 2011 9:52:00 AM

Rank: Administration
Groups: Administration

Joined: 11/23/2008
Posts: 335
Points: 711
Location: Australia
I had a situation where I need to use a string array in sql where-in clause
Code:
strQuery = String.Format(strQuery, String.Join(",", stringArray)


I also need to convert an integer array to the string array. I did the conversion by iterating through the array.

If you don't want to do this way, there are other ways available from .net and linq:
1.
a)
Code:

//...
string[] stringArray =
Array.ConvertAll<int,string>
(intArray,new Converter<int,string>
(ConvertIntToString));
//...


private string ConvertIntToString(int intParameter)
{
return intParameter.ToString();
}


b) a compact form
Code:
string[] stringArray = Array.ConvertAll<int,string>(ids, delegate(int intParameter) {return intParameter.ToString();});


2. linq
a)
Code:
Array.ConvertAll<int, string>(INTARRAY, intParameter => intParamter.ToString());


b)
Code:
var STRINGARRAY = INTARRAY.Select(s => s.ToString());


c)
Code:
string[] stringArray = intArray.Select(i => i.ToString()).ToArray();
Sponsor
Posted: Monday, March 28, 2011 9:52:00 AM
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

ASPNET Theme created by Boskone (Dan Ferguson)
Powered by Yet Another Forum.net version 1.9.1.8 (NET v2.0) - 3/29/2008
Copyright © 2003-2008 Yet Another Forum.net. All rights reserved.
This page was generated in 0.050 seconds.