Click here to Skip to main content
15,918,330 members
Home / Discussions / C#
   

C#

 
GeneralRe: Dictionary Problem Pin
N a v a n e e t h11-Oct-09 22:17
N a v a n e e t h11-Oct-09 22:17 
GeneralRe: Dictionary Problem Pin
egpuyos11-Oct-09 22:28
egpuyos11-Oct-09 22:28 
Actually Sir, it was just my sample code, the real code I have is this.

I don't understand why that the dictionary when I call the method Exists, it will return false while it already contain the key that I passed? How could it happen?

Thank you again with you're help Sir.

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        private static Dictionary<byte[], string> m_MyDictionary = null;
        private static System.Text.ASCIIEncoding m_MyEncoding = new ASCIIEncoding();

        static void Main(string[] args)
        {
            m_MyDictionary = new Dictionary<byte[], string>();
            AddDataToDictionary();
            Console.Write(Exists(m_MyEncoding.GetBytes("test 003")));
            Console.Read();
        }

        private static void AddDataToDictionary()
        {
            string s;
            byte[] myByte;

            s = "test 001";
            myByte = m_MyEncoding.GetBytes(s);
            m_MyDictionary.Add(myByte, s);

            s = "test 002";
            myByte = m_MyEncoding.GetBytes(s);
            m_MyDictionary.Add(myByte, s);

            s = "test 003";
            myByte = m_MyEncoding.GetBytes(s);
            m_MyDictionary.Add(myByte, s);

            s = "test 004";
            myByte = m_MyEncoding.GetBytes(s);
            m_MyDictionary.Add(myByte, s);

            s = "test 0021537912";
            myByte = m_MyEncoding.GetBytes(s);
            m_MyDictionary.Add(myByte, s);

            s = "test 327487";
            myByte = m_MyEncoding.GetBytes(s);
            m_MyDictionary.Add(myByte, s);
        }

        private static bool Exists(byte[] key)
        {
            return m_MyDictionary.ContainsKey(key);
        }
    }
}

GeneralRe: Dictionary Problem Pin
Luc Pattyn12-Oct-09 0:12
sitebuilderLuc Pattyn12-Oct-09 0:12 
GeneralRe: Dictionary Problem Pin
egpuyos11-Oct-09 22:14
egpuyos11-Oct-09 22:14 
GeneralRe: Dictionary Problem Pin
freakyit11-Oct-09 22:29
freakyit11-Oct-09 22:29 
Questionregarding auto generated mail in window application Pin
NarendraSinghJTV11-Oct-09 21:43
NarendraSinghJTV11-Oct-09 21:43 
AnswerRe: regarding auto generated mail in window application Pin
SeMartens11-Oct-09 21:49
SeMartens11-Oct-09 21:49 
GeneralRe: regarding auto generated mail in window application Pin
NarendraSinghJTV11-Oct-09 22:55
NarendraSinghJTV11-Oct-09 22:55 
QuestionProblem with RichText Box(Right Click Cut/Copy/Paste/SelectAll)... Pin
spalanivel11-Oct-09 21:41
spalanivel11-Oct-09 21:41 
AnswerRe: Problem with RichText Box(Right Click Cut/Copy/Paste/SelectAll)... Pin
Lyon Sun11-Oct-09 22:01
Lyon Sun11-Oct-09 22:01 
GeneralRe: Problem with RichText Box(Right Click Cut/Copy/Paste/SelectAll)... Pin
spalanivel11-Oct-09 22:06
spalanivel11-Oct-09 22:06 
GeneralRe: Problem with RichText Box(Right Click Cut/Copy/Paste/SelectAll)... Pin
Lyon Sun11-Oct-09 22:26
Lyon Sun11-Oct-09 22:26 
AnswerRe: Problem with RichText Box(Right Click Cut/Copy/Paste/SelectAll)... Pin
dan!sh 11-Oct-09 22:07
professional dan!sh 11-Oct-09 22:07 
QuestionTo modify table column. Pin
kmb8911-Oct-09 19:54
kmb8911-Oct-09 19:54 
AnswerRe: To modify table column. Pin
SeMartens11-Oct-09 21:51
SeMartens11-Oct-09 21:51 
GeneralRe: To modify table column. Pin
kmb8911-Oct-09 22:14
kmb8911-Oct-09 22:14 
GeneralRe: To modify table column. Pin
SeMartens11-Oct-09 22:21
SeMartens11-Oct-09 22:21 
GeneralRe: To modify table column. Pin
kmb8911-Oct-09 22:51
kmb8911-Oct-09 22:51 
AnswerRe: To modify table column. Pin
Md. Marufuzzaman11-Oct-09 23:37
professionalMd. Marufuzzaman11-Oct-09 23:37 
GeneralRe: To modify table column. Pin
Md. Marufuzzaman11-Oct-09 23:41
professionalMd. Marufuzzaman11-Oct-09 23:41 
QuestionTimeout expired Pin
MozhdehQeraati11-Oct-09 19:12
MozhdehQeraati11-Oct-09 19:12 
AnswerRe: Timeout expired Pin
Saksida Bojan11-Oct-09 23:03
Saksida Bojan11-Oct-09 23:03 
AnswerRe: Timeout expired Pin
Md. Marufuzzaman11-Oct-09 23:48
professionalMd. Marufuzzaman11-Oct-09 23:48 
AnswerRe: Timeout expired Pin
Luc Pattyn12-Oct-09 0:15
sitebuilderLuc Pattyn12-Oct-09 0:15 
AnswerRe: Timeout expired Pin
Dave Kreskowiak12-Oct-09 8:25
mveDave Kreskowiak12-Oct-09 8:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.