This program is show int array and String array in two methods. Following is the code snippet for this and you can download the source project in click the download icon.
C#.net Code for Array
Download Project
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 Array_1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void inta1button_Click(object sender, EventArgs e) { listBox1.Items.Clear(); int[] numbers= new int[5]; numbers[0] = 50; numbers[1] = 25; numbers[2] = 40; numbers[3] = 15; numbers[4] = 10; for (int i = 0; i < numbers.Length; i++) { listBox1.Items.Add(numbers[i]); listBox1.Items.Add(""); } } private void inta2button_Click(object sender, EventArgs e) { listBox1.Items.Clear(); int[] numbers = {55,25,45,15,10 }; for (int i = 0; i < numbers.Length; i++) { listBox1.Items.Add("Number ["+i+"]"+"==>"+numbers[i]); listBox1.Items.Add(""); } } private void stringa1button_Click(object sender, EventArgs e) { listBox2.Items.Clear(); string[] names = new string[5]; names[0] = "Nadeera"; names[1] = "Chathuranga"; names[2] = "Bandaranayake"; names[3] = "ncb"; names[4] = "cvbn"; foreach (string item in names) { listBox2.Items.Add(item); listBox2.Items.Add (""); } } private void stringa2button_Click(object sender, EventArgs e) { listBox2.Items.Clear(); string[] names = {"Dell","laptop","are","best","one" }; foreach (string item in names) { listBox2.Items.Add(item); listBox2.Items.Add(""); } } } }
Thanks Sudhir
ReplyDelete