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;
using System.Collections; // firstly add namespace to use array list
namespace Use_Array_List
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnarraylist_Click(object sender, EventArgs e)
{
//array list store any type of value like as : integer , char, string, float etc;
ArrayList arrlist = new ArrayList();
arrlist.Add("1");
arrlist.Add("2");
arrlist.Add(3);
foreach(string val in arrlist)
{
listBox1.Items.Add(val);
}
}
private void btnUseDict_Click(object sender, EventArgs e)
{
Dictionary<string, int> dic = new Dictionary<string, int>();
dic.Add("One", 1); // we can use name place of one two three , like sumit , sum
dic.Add("two", 2);
dic.Add("three", 3);
dic.Add("four", 4);
foreach (var val in dic)
{
listBox1.Items.Add("Key is :"+val.Key+",Value of Key is :"+val.Value);
}
}
}
}
Comments
Post a Comment