Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
protected void ddlCircle_SelectedIndexChanged(object sender, EventArgs e)
   {
     ArrayList list = new ArrayList();

     ShadingAnalysisDataSetTableAdapters.tbl_CadEngineersTeamTableAdapter cd;
     cd = new ShadingAnalysisDataSetTableAdapters.tbl_CadEngineersTeamTableAdapter();
     DataTable dt = new DataTable();
     dt = cd.GetAvailableData(ddlCircle.SelectedValue);

     int x;
     x = dt.Rows.Count;

       String [] a;
       String [] b = { "Team" };
       for (int i = 1; i <= x; i++)
       {
           a = b + i; // error popup here
       }
  }
Posted
Comments
Sinisa Hajnal 24-Oct-14 2:29am    
So, what is the question? You could do this: String a = "test"; int i = 1; a + i.ToString = "test1", but you're trying to add string arrays. What do you expect as the result of your operation?

Your b is single element array...why not have String b = "Team"?
Maciej Los 24-Oct-14 2:33am    
Why do you use arrays of string? Use:
String a = String.Empty();
String b= String.Empty();
.
And inside the loop: a += b + i.ToString();

Try:
That is some very odd code: it's not obvious exactly what you expect to get out of it - but there are more errors in there than you have seen so far!
First off, a is an array of strings - except you haven't allocated any space to hold the data.
Second, why is b and array of strings if you are only putting one element in there, and use the same element each time? Why not just a string?
Third, what do you expect the code
C#
a = b + i;
To actually do? Particularly in a loop?
Since you don't change b inside the loop, the whole loop can be replaced with a single statement using x since a would always contain the same value after it finishes anyway.
And a is an array (with no data), b is an array (with one element) and i is an integer - so I can't see anything particularly useful going into a anyway.

Think about what you are trying to achieve, rather than what you have written so far: because I think you have lost track of that - I suspect you meant to use dt in there somewhere to use the data you retrieved in the earlier code!
 
Share this answer
 
The intent here seems to generate the array of x teams with names Teamx. Please change your naming to better reflect the intent of the variable.

Do this:
C#
ArrayList teamList = new ArrayList;

for (int i = 1; i <= x; i++)
        {
            teamList.Add(String.Format("Team{0}", i)); 
        }


And if you really need string array then use
C#
String [] teams;
teams = teamList.ToArray(typeof( string ));
 
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