NAVEEN PANERU

NAVEEN PANERU

  • NA
  • 25
  • 1.1k

problem while running for loop.

Apr 7 2016 1:14 AM
I designed a windows application form NAVIGATOR, and put the following code to the form.
When I am passing the parameters "string" and "int" to the function Hereitis. e.g if I pass "naveen" and "1", then It's output must be as:
 
HI naveen
HI naveen naveen     but in second time or further as per the "numberoftimes" it always prints HI naveen only. why the value of finalstring is not getting modified each time for loop runs..???? 
 
 
namespace Navigator
{
class Talker
{
public static int Hereitis(string thingTosay, int numberoftimes)
{
string finalstring = " HI ";
for (int count = 0; count <= numberoftimes; count++)
{
finalstring = finalstring + thingTosay + "\n";
}
MessageBox.Show(finalstring);
return finalstring.Length;
 
 
 

Answers (25)