Dictionary with delegate or swith?

Posted by Samvel Siradeghyan on Stack Overflow See other posts from Stack Overflow or by Samvel Siradeghyan
Published on 2010-05-24T11:49:00Z Indexed on 2010/05/24 11:51 UTC
Read the original article Hit count: 414

Hi,
I am writting a parser, which call some functions dependent on some value.
I can implement this logic with simple switch like this
swith(some_val)
{
case 0:
func0();
break;
case 1:
func1();
break;
}

or with delegates and dictinary like this

delegate void some_delegate();
Dictinary some_dictinary = new Dictinary();
some_dictinary[0] = func0;
some_dictinary[1] = func1;

some_dictinary[some_value].Invoke();

Are this two metods equal and wich is prefered?
Thanks.

© Stack Overflow or respective owner

Related posts about c#

Related posts about dictionary