Switch Statment in C# .Net and difference between if else and Switch statment?

1) Switch statement includes one or more switch section.Each section contains on eor more case labels followed by one or more statement .

2) Each case label specifies a constant value. The switch section transfer control to switch section whose label matches. If you write default section in switch block then if any case is not matched with case-control goes to default section.

3) Their is small difference between if-else and switch statement.If cases their is no significant performance difference but if the case are more then MSIL will generate a jump table or hashtable and matching cases are done vai lookup which considerable difference in if else and switch.



Comments