如何使用循环显示数据 [英] How to display data with looping

查看:69
本文介绍了如何使用循环显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以为什么数据的结果:3,应该记录:test / 123



我尝试了什么:



示例数据:test / 123



此功能:

  for  int  i =  0 ; i < (receiveBufferLen  -   2 ); i ++)
{

会话[ ] =()receiveBuffer [I];
TextBox1.Text = data: +(char)receiveBuffer [i]);
}







i调用文本框:

 TextBox1。 Text =   data: + Session [ ]。ToString(); 







请给我解决方案..

解决方案

如果你的循环看起来像这样:

  int  total =  0 ; 
for int i = 0 ; i < 10 ; i ++)
{
total = i;
}
Console.WriteLine(total) ;

那么你会明白什么时候打印的值总是9,而不是45,因为你没有将数据加在一起 ​​- 你每次都要替换总数。

你知道如何修复它:

  int  total =  0 ; 
for int i = 0 ; i < 10 ; i ++)
{
total = total + i;
}
Console.WriteLine(总);



你问题中的循环做同样的事情,解决方案也是一样的!


so why the results of the data: 3, should the record: test / 123

What I have tried:

example data : test / 123

this function :

for (int i = 0; i < (receiveBufferLen - 2); i++)
{

   Session ["Value"] = (char)receiveBuffer[i];
   TextBox1.Text = data : " + (char)receiveBuffer[i]);
}




i call on the textbox :

TextBox1.Text = "data : "+ Session["Value"].ToString();




please give me solution..

解决方案

If your loop looked like this:

int total = 0;
for (int i = 0; i < 10; i++)
   {
   total = i;
   }
Console.WriteLine(total);

Then you would understand when the value printed was always 9, rather than 45, because you don't add the data together - you replace the total each time.
And you know how to fix it:

int total = 0;
for (int i = 0; i < 10; i++)
   {
   total = total + i;
   }
Console.WriteLine(total);


Your loop in the question does the same thing, and the solution is the same as well!


这篇关于如何使用循环显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆