Click here to Skip to main content
15,884,472 members
Home / Discussions / C#
   

C#

 
AnswerRe: Downloading an image from web Pin
Luc Pattyn26-Mar-12 14:28
sitebuilderLuc Pattyn26-Mar-12 14:28 
AnswerRe: Downloading an image from web Pin
Abhinav S26-Mar-12 15:35
Abhinav S26-Mar-12 15:35 
GeneralRe: Downloading an image from web Pin
Jack Li26-Mar-12 22:06
Jack Li26-Mar-12 22:06 
AnswerRe: Downloading an image from web Pin
kingNull26-Mar-12 23:30
kingNull26-Mar-12 23:30 
GeneralRe: Downloading an image from web Pin
Muammar©27-Mar-12 10:23
Muammar©27-Mar-12 10:23 
GeneralRe: Downloading an image from web Pin
Pete O'Hanlon27-Mar-12 10:40
mvePete O'Hanlon27-Mar-12 10:40 
AnswerRe: Downloading an image from web Pin
V.26-Mar-12 23:51
professionalV.26-Mar-12 23:51 
QuestionMessenger Class Problem Pin
Kevin Marois26-Mar-12 8:08
professionalKevin Marois26-Mar-12 8:08 
I'm trying to refactor this messenger class so that it's generic, but I'm getting a compile error.

private Dictionary<Type, List<Action<object>>> internalList;

public void Register<T>(Action<T> callback)
{
    Type messageType = typeof(T);
    List<Action<T>> list;

    if (internalList == null)
    {
        internalList = new Dictionary<Type, List<Action<object>>>();
    }

    if (!internalList.ContainsKey(messageType))
    {
        list = new List<Action<T>>();
        internalList.Add(messageType, list);
    }
    else
    {
        list = internalList[messageType];
    }

    list.Add(callback);
}


It doesn't like either

internalList.Add(messageType, list);


or

list = internalList[messageType];


I don't understand why because the Dictionary is defined to accept a
List<Action<object>>
. So the 2 lines above should work, right?

What am I doing wrong here?
Everything makes sense in someone's mind

AnswerRe: Messenger Class Problem Pin
SledgeHammer0126-Mar-12 8:23
SledgeHammer0126-Mar-12 8:23 
GeneralRe: Messenger Class Problem Pin
Kevin Marois26-Mar-12 10:34
professionalKevin Marois26-Mar-12 10:34 
GeneralRe: Messenger Class Problem Pin
SledgeHammer0126-Mar-12 10:48
SledgeHammer0126-Mar-12 10:48 
GeneralRe: Messenger Class Problem Pin
Kevin Marois26-Mar-12 10:50
professionalKevin Marois26-Mar-12 10:50 
GeneralRe: Messenger Class Problem Pin
SledgeHammer0126-Mar-12 11:06
SledgeHammer0126-Mar-12 11:06 
AnswerRe: Messenger Class Problem Pin
BobJanova27-Mar-12 4:58
BobJanova27-Mar-12 4:58 
QuestionIdentify which Element fired event handler code-behind. Pin
cknight72526-Mar-12 6:28
cknight72526-Mar-12 6:28 
AnswerRe: Identify which Element fired event handler code-behind. PinPopular
Luc Pattyn26-Mar-12 6:40
sitebuilderLuc Pattyn26-Mar-12 6:40 
GeneralRe: Identify which Element fired event handler code-behind. Pin
cknight72527-Mar-12 7:23
cknight72527-Mar-12 7:23 
GeneralRe: Identify which Element fired event handler code-behind. Pin
Luc Pattyn27-Mar-12 7:39
sitebuilderLuc Pattyn27-Mar-12 7:39 
QuestionDoes anyone have a method that read raw bits or bytes? Pin
turbosupramk326-Mar-12 5:43
turbosupramk326-Mar-12 5:43 
AnswerRe: Does anyone have a method that read raw bits or bytes? Pin
PIEBALDconsult26-Mar-12 5:58
mvePIEBALDconsult26-Mar-12 5:58 
GeneralRe: Does anyone have a method that read raw bits or bytes? Pin
turbosupramk326-Mar-12 8:16
turbosupramk326-Mar-12 8:16 
GeneralRe: Does anyone have a method that read raw bits or bytes? Pin
harold aptroot26-Mar-12 6:59
harold aptroot26-Mar-12 6:59 
GeneralPrevious: Can read 64bit Reg_Sz, but not 64bit D_Word [modified] Pin
Eddy Vluggen26-Mar-12 7:30
professionalEddy Vluggen26-Mar-12 7:30 
GeneralRe: Previous: Can read 64bit Reg_Sz, but not 64bit D_Word [modified] Pin
harold aptroot26-Mar-12 7:48
harold aptroot26-Mar-12 7:48 
GeneralRe: Previous: Can read 64bit Reg_Sz, but not 64bit D_Word [modified] Pin
turbosupramk326-Mar-12 8:17
turbosupramk326-Mar-12 8:17 

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.