Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dictionary with delegate or switch?

Tags:

I am writing a parser which calls some functions dependent on some value.

I can implement this logic with simple switch like this:

switch(some_val)    {        case 0:            func0();            break;        case 1:            func1();            break;    }      

or with delegates and a dictionary like this:

delegate void some_delegate();    Dictionary<int, some_delegate> some_dictionary = new Dictionary<int, some_delegate>();    some_dictionary[0] = func0;    some_dictionary[1] = func1;     some_dictionary[some_value].Invoke();     

Are these two methods equivalent and which is preferred?