InvalidCastException when getting Text from a Label referenced by dynamicaly built String, Fix?
<p>NET Version: 3.5
Ok, I recieve an error (System.InvalidCastException was unhandled. Message="Unable to cast object of type 'System.Windows.Forms.Control[]' to type 'System.Windows.Forms.Label'.") when trying to get Text from a Label referenced by a dynamicly built string.</p>

<p>Here's my situation; I have an array of 250 labels named l1 - l250. What I want to do is loop through them using this while statement: </p>

<pre><code>int c = 1; 
while (c &lt; 251) 
{ 
string k = "l" + c.ToString(); //dynamic name of Control(Label) 
object ka = Controls.Find(k, true);  
string ct = ((Label)ka).Text;  //&lt;&lt;Error Occurs Here 
build = build + ct; 
c++; 
}
</code></pre>

<p>and get the text value of each to build a string named build.</p>

<p>I don't get any build errors, just this while debuging.</p>

<p>While debuging I can go down to view my local variables. When looking through these, I can view the contents of object ka; it does contain the correct Text value of the correct Label I want to "access". I just don't understand how to get there. The text value is listed under "[0]" which is the only subcatagory for "ka". </p>
