0% found this document useful (0 votes)
7 views3 pages

Collections

Uploaded by

rupams2024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Collections

Uploaded by

rupams2024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

using System;

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Collection_GenericCollections
{
class Program
{
static void Main(string[] args)
{
//List_1();
//Dictionary_1();
//ArrayList_1();
HashTable_1();

Console.ReadKey();
}

private static void ArrayList_1()


{
ArrayList list = new ArrayList();
list.Add("Visual Basic");
list.Add(344);
list.Add(55);
list.Remove(55);

foreach (object obj in list)


{
Console.WriteLine(obj);
}
}

private static void HashTable_1()


{
Hashtable hashTable = new Hashtable();
hashTable.Add("1", "s");
hashTable.Add("3", "n");
hashTable.Add("5", "o");
hashTable.Add("2", "a");
hashTable.Add("4", "t");

foreach(object i in hashTable.Keys)
{
Console.WriteLine(i);
}
Console.WriteLine("***********************************");
foreach (object i in hashTable.Values)
{
Console.WriteLine(i);
}
Console.WriteLine("***********************************");
foreach (DictionaryEntry i in hashTable)
{
Console.WriteLine($"Key:{i.Key}, Value:{i.Value}");
}
}
private static void Dictionary_1()
{
Dictionary<string, string> domains = new Dictionary<string, string>();
domains.Add("de", "Germany");
domains.Add("sk", "Slovakia");
domains.Add("us", "United States");
domains.Add("ru", "Russia");
domains.Add("hu", "Hungary");
domains.Add("pl", "Poland");

Console.WriteLine(domains["sk"]);
Console.WriteLine(domains["pl"]);

Console.WriteLine($"Dictionary has {domains.Count} items.");


//**********************************************//
Console.WriteLine("Keys of the dictionary:");
List<string> keys = new List<string>(domains.Keys);
foreach(string key in keys)
{
Console.WriteLine(key);
}
Console.WriteLine("Values of the dictionary:");
List<string> values = new List<string>(domains.Values);
foreach(string value in values)
{
Console.WriteLine(value);
}
Console.WriteLine("Keys and Values of the dictionary:");
foreach(KeyValuePair<string,string> kvp in domains)
{
Console.WriteLine($"Key: {kvp.Key} , Value: {kvp.Value}");
}
}

private static void List_1()


{
List<string> langs = new List<string>();
langs.Add("Java");
langs.Add("C#");
langs.Add("C");
langs.Add("C++");
langs.Add("Ruby");
langs.Add("Javascript");

Console.WriteLine(langs.Contains("C#"));
Console.WriteLine(langs[2]);
Console.WriteLine(langs[5]);

langs.Remove("C++");
langs.Remove("Java");

Console.WriteLine(langs.Contains("Java"));

langs.Insert(2, "Jquery");
langs.Insert(4, "Python");

langs.Sort();
foreach (string lang in langs)
{
Console.WriteLine(lang);
}
}
}
}

You might also like