Finding count through a dynamically created variable in a loop in c#
<p>I have few variables named as am_2,am_1,am_3 and so on.
I have to find the count by typing: <code>am_2.Count(), am_1.Count()</code> and so on.
I want to do the same in a loop. Right now I will have to write all of them separately like: </p>

<pre><code>am_2.Count(),am_1.Count(),am_3.Count().... 
</code></pre>

<p>Is there a way that I can get the Count by not typing the variable name again and again and can do it in a loop. I tried the following code, but it did not work:</p>

<pre><code>for(i=1;i&lt;=12;i++)
{
string sm="am_"+1;

if(sm.Count()==1)
{
 Do the task.....
 }

  }
</code></pre>

<p>But the above code does not work. Any suggestions?</p>