Question: String concatenation in a loop. I get this bug when i tested my project in klocwork. i am concatenating many strings in loop is it a big mistake .

```
for(int j=0;j<nAttr;j++)
{
    builder = new StringBuilder();
    size=rnd.Next(1,10);
    for(int k=0; k<size; k++)
    {
        ch = Convert.ToChar(Convert.ToInt32(26 * rnd.NextDouble() + 65)) ;
        if(ch=='[' || ch==']')
            j--;
        else
            builder.Append(ch); 
    }
    strXml+=" "+builder.ToString();//here the bug arises 
    strXml+="="+"\"";

```

i also found this bug when i tested 

Class/struct data member is hidden by a local variable what does it mean 

```
private void TraverseValues(XmlNode n,ArrayList arr)
{
    if(n.HasChildNodes )
    {   
        for(int i=0;i<n.ChildNodes.Count;i++)
        {
            if(n.ChildNodes[i].Name=="#text")
                arr.Add(n.ChildNodes[i].InnerText );
            else    
                TraverseValues(n.ChildNodes[i],arr)//here the code arises 

```

i completed my project .it works fine then i tested my product with klocwork it suggested these bugs .but i am not able to understand y it says it has critical error in code

Answer: 
Klickwork creates a static analysis application.

I think Arunachalam refers to some static analysis assertion as "bug".

When strXml is of string type then it would be possible that static analysis will show `strXml+=" "+builder.ToString();` as bad code (a "bug").

From the code posted it is definitely not bug in the core .NET Library.
What type of Bug do you expect there to be? Could you post more of your code, so that we can se, what should come out of this operation?

I just scrapped your code into a new project, cleaned the code a little bit up, but it seems to work like expected.

```
StringBuilder builder;
            int nAttr = 5;
            int size;
            char ch;
            Random rnd = new Random();
            for(int j=0;j<nAttr;j++)
            {
               builder = new StringBuilder();
                builder.Append(" ");
                size=rnd.Next(1,10);
                    for(int k=0; k<size; k++)
                    {
                            ch = Convert.ToChar(Convert.ToInt32(26 * rnd.NextDouble() + 65)) ;
                            if(ch=='[' || ch==']')
                                    j--;
                            else
                                    builder.Append(ch); 
                    }
                builder.Append("=\"");
                Console.WriteLine(builder.ToString());
            }

```

One thing I do not understand is why do you use a StringBuilder, then concatenate the result of the StringBuilder with a literal to a new string and concatenate that again. You should use your StringBuilder to build the whole string, the export the result.