88 lines
2.1 KiB
C#
88 lines
2.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Hash
|
|
{
|
|
internal class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
Hashtable hashtable = new Hashtable();
|
|
hashtable.Add("A1", "Welcome");
|
|
hashtable.Add("A2", "to");
|
|
hashtable.Add("A3", "Hell");
|
|
|
|
if (hashtable.Contains("A2"))
|
|
{
|
|
Console.WriteLine("Contains");
|
|
} else
|
|
{
|
|
Console.WriteLine("Not contains");
|
|
}
|
|
|
|
if (hashtable.ContainsValue("Hell"))
|
|
{
|
|
Console.WriteLine("Contains");
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Not contains");
|
|
}
|
|
|
|
|
|
|
|
hashtable.Remove("A2");
|
|
|
|
if (hashtable.ContainsKey("A2"))
|
|
{
|
|
Console.WriteLine("Contains");
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Not contains");
|
|
}
|
|
|
|
Console.WriteLine("Key and Value pairs from hashtable:");
|
|
|
|
|
|
|
|
|
|
foreach (DictionaryEntry element in hashtable) {
|
|
Console.WriteLine($"Key: {element.Key}, Value: {element.Value}");
|
|
}
|
|
|
|
Hashtable hashtable2 = new Hashtable()
|
|
{
|
|
{1, "Hello" },
|
|
{2, 234 },
|
|
{3, 230.45 },
|
|
{4, null }
|
|
};
|
|
|
|
hashtable2.Clear();
|
|
|
|
foreach (var element in hashtable2.Keys) {
|
|
Console.WriteLine($"Key: {element}, Value: {hashtable2[element]}");
|
|
}
|
|
|
|
string keyToUpdate = "A1";
|
|
|
|
if (hashtable.ContainsKey(keyToUpdate))
|
|
{
|
|
hashtable[keyToUpdate] = "new value";
|
|
}
|
|
|
|
string updatedValue = (string)hashtable[keyToUpdate];
|
|
Console.WriteLine($"Updated value: {updatedValue}");
|
|
|
|
|
|
Console.ReadLine();
|
|
}
|
|
}
|
|
}
|