Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

i am using this dictionary for input data in C# .net wpf application.

C#
Dictionary<int, string> dic = new Dictionary<int, string>();
            dic.Add(1, "E");
            dic.Add(2, "G");
            dic.Add(3, "$");
            dic.Add(4, "/");
            dic.Add(5, "!");
            dic.Add(6, "P");
            dic.Add(7, "*");
            dic.Add(8, "@");
            dic.Add(9, "Q");
            dic.Add(0, "U");


But how can i use this dictionary?

When in enter 12 so then EG should be display in text box.
and when i enter 5 so ! should be display in textbox.

Total should be calculate like 12+5=17 (E*).

Please help me.

Thanks in Advance.

Ankit Agarwal
Software Engineer
Posted

Please read this:
http://www.dotnetperls.com/dictionary[^]
It also explains how to get keys resp. values.
 
Share this answer
 
Comments
[no name] 27-Mar-15 5:48am    
But its a console application i have to use in wpf windows application.
TheRealSteveJudge 27-Mar-15 6:06am    
The examples at www.dotnetpears.com are console apps. That's right.
Your question was about "How to use dictionary".
In a WPF application dictionaries can be used the same way than in a console app.
C#
public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            dic.Add(1, "E");
            dic.Add(2, "G");
            dic.Add(3, "$");
            dic.Add(4, "/");
            dic.Add(5, "!");
            dic.Add(6, "P");
            dic.Add(7, "*");
            dic.Add(8, "@");
            dic.Add(9, "Q");
            dic.Add(0, "U");
        }
        public static Dictionary<int, string> dic = new Dictionary<int, string>();

        private void txt_TextChanged(object sender, TextChangedEventArgs e)
        {
            txtval.Text = "";
            char[] str = txt.Text.ToArray();
            foreach (char items in str)
            {
                var cx = (from t in dic where t.Key == Convert.ToInt32(items.ToString()) select t);
                foreach (var item in cx)
                {
                    txtval.Text += item.Value;

                }
            }
            //dic.Select(t => t.Key == Convert.ToInt32(txt.Text)).Select(t => t).ToString(); //dic.Select(t => t.Key == Convert.ToInt32(txt.Text));
        }
    }
 
Share this answer
 
Comments
[no name] 27-Mar-15 7:25am    
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900