using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace zSharp2010.Dictionary
{
class cDictionary
{
//Create the dictionary.
private Dictionary dictionary = new Dictionary();
///
/// Populate the dictionary with key and customer.
///
public void SetValues()using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace zSharp2010.Dictionary
{
class cDictionary
{
//Create the dictionary.
private Dictionary
///
/// Populate the dictionary with key and customer.
///
{
for (int i = 1; i <= 10; i++)
{
//Use AAA, BBB, CCC etc as name.
char letter = (char) (i + 64);
Customer customer = new Customer();
customer.ID = i * 10;
customer.Name = letter.ToString () + letter.ToString () + letter.ToString ();
dictionary.Add(i, customer);
}
}
public string GetValues(int key)
{
string result = string.Empty;
//If key is valid then return the key value.
if (key != 0)
{
Customer customer = dictionary[key];
result += string.Format("{0} : {1}, {2}\r\n", key, customer.ID.ToString(), customer.Name);
}
//else return the complete dictionar information.
else
{
for (int i = 01; i <= dictionary.Count; i++)
{
Customer customer = dictionary[i];
result += string.Format("{0} : {1}, {2}\r\n", i, customer.ID.ToString(), customer.Name);
}
}
return result;
}
}
//The customer class.
class Customer
{
public int ID { get; set; }
public string Name{get; set;}
}
}
}
Add a comment