WPF For循环和For循环 [英] WPF For loop and For each loop

查看:919
本文介绍了WPF For循环和For循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WPF,我遇到了for循环和每个循环的问题。

 For(int I = 0; I< 10; i ++)

{

TextBox1.Text = I.ToString()

}




 string [] A = {" A"," B"," C"," D" }; 

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

textBox2.Text = A [i] .ToString();
}

这个有效,但我认为他们是一种使用for循环做同样事情的方法。 for循环和每个循环的任何示例都有帮助谢谢

 var result = Enumerable.Range(0,10).Select(i => i.ToString( ))。Aggregate((init,next)=> init + Environment.NewLine + next); 
textBox1.Text = result;







解决方案



而不是你的Enumerable.Range ...你可以使用这个循环:

 string result = string.Empty; 
for(int i = 0; i< 10; i ++)result + =(string.IsNullOrEmpty(result))?


" {i}" :

" {Environment.NewLine} {I}英寸;
TextBox3.Text = result;


I am working with WPF and I am having issues with for loop and for each loops.

For(int I = 0; I < 10; i++)

{

TextBox1.Text = I.ToString()

}


string[] A = { "A", "B", "C", "D" };

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

               textBox2.Text = A[i].ToString();
            }

This one works but i would think their is a way to uses a for loop to do the same thing as this. Any examples of for loops and for each loops would help thanks

 var result = Enumerable.Range(0, 10).Select(i => i.ToString()).Aggregate((init, next) => init + Environment.NewLine + next);
            textBox1.Text = result;



解决方案

Hi,
instead of yours Enumerable.Range… you can use this loop:

        string result = string.Empty;
        for (int i = 0; i < 10; i++) result += (string.IsNullOrEmpty(result)) ?


"{i}" :


"{Environment.NewLine}{i}"; TextBox3.Text = result;


这篇关于WPF For循环和For循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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