using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DictionaryCode
{
class Program
{
static void Main(string[] args)
{
string name;
Dictionary<string, string> FictionalHeroes = new Dictionary<string, string>();
FictionalHeroes.Add("Barry Allen","Flash");
FictionalHeroes.Add("Bruse Wayne", "Batman");
FictionalHeroes.Add("Oliver Queen", "Green Arrow");
FictionalHeroes.Add("Saitama", "One Punch man");
FictionalHeroes.Add("Kent Clark", "Superman");
foreach (KeyValuePair<string,string> o in FictionalHeroes)
{
Console.WriteLine("{0} is the {1}",o.Key,o.Value);
}
FictionalHeroes.Remove("Kent Clark");
Console.WriteLine("The FictionalHeroes are {0}",FictionalHeroes.Count);
Console.WriteLine("The FictionalHeroes contains key Saitama: {0}", FictionalHeroes.ContainsKey("Saitama"));
FictionalHeroes.TryGetValue("Saitama",out name);
Console.WriteLine(name);
FictionalHeroes.Clear();
Console.ReadKey();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DictionaryCode
{
class Program
{
static void Main(string[] args)
{
string name;
Dictionary<string, string> FictionalHeroes = new Dictionary<string, string>();
FictionalHeroes.Add("Barry Allen","Flash");
FictionalHeroes.Add("Bruse Wayne", "Batman");
FictionalHeroes.Add("Oliver Queen", "Green Arrow");
FictionalHeroes.Add("Saitama", "One Punch man");
FictionalHeroes.Add("Kent Clark", "Superman");
foreach (KeyValuePair<string,string> o in FictionalHeroes)
{
Console.WriteLine("{0} is the {1}",o.Key,o.Value);
}
FictionalHeroes.Remove("Kent Clark");
Console.WriteLine("The FictionalHeroes are {0}",FictionalHeroes.Count);
Console.WriteLine("The FictionalHeroes contains key Saitama: {0}", FictionalHeroes.ContainsKey("Saitama"));
FictionalHeroes.TryGetValue("Saitama",out name);
Console.WriteLine(name);
FictionalHeroes.Clear();
Console.ReadKey();
}
}
}
Comments
Post a Comment