Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
ShadingAnalysisDataSetTableAdapters.tbl_CadEngineersTeamTableAdapter cd;

cd = new ShadingAnalysisDataSetTableAdapters.tbl_CadEngineersTeamTableAdapter();

DataTable dt2 = new DataTable();

dt2 = cd.GetAssignTeam(x);

object a = cd.GetAssignTeam(x);

string[] b = a.ToString(); // error popup here
Posted

Hi,

In the code
C#
string[] b = a.ToString();
you are assigning a string object to array. You will have to assign a string array type object to it.

A string is an object of type String whose value is text. Internally, the text is stored as a sequential read-only collection of Char objects.
While a string array is a collection of strings. Hence, you cannot assign that way.

Try converting a object to string array and then assigning it to the array.

For e.g in your code try:
string[] b = ((System.Collections.IEnumerable)a).Cast<object>().Select(x => x.ToString()).ToArray();


Hope this helps !! :)

Regards,
Praneet
 
Share this answer
 
Hello ,
.ToString() retuns single string rather than string array . so check your code before execution .
 
Share this answer
 
v2
Hi,

Every array implements IEnumerable. You can use that functionality here.

Try this code

C#
string[] b = ((IEnumerable)obj).Cast<object>()                               .Select(x => x.ToString()).ToArray();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900