Description :
In this example, we are using (for loop)statement to show counting on listbox.
Ingredients:
1) One List Box
2) One Button
Programming (Ascending Order) :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int A;
for (A = 1; A < 10; A++ )
{
listBox1.Items.Add(A);
}
int B;
for (B = 1; B < 10; B++)
{
listBox1.Items.Add(B);
}
}
}
}
Output:
1 to 9
Programming (Decending Order):
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int B;
for (B = 10-1; B >= 0; B--)
{
listBox1.Items.Add(B);
}
}
}
}
Output :
9 to 1
No comments:
Post a Comment