且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

WPF For循环和For循环

更新时间:2022-10-15 09:19:21



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

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


" {i}" :

&QUOT; {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;