Lecture overview -- Keyboard shortcut: 'u'  Previous page: Operators -- Keyboard shortcut: 'p'  Next page: Functions -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 14 : 43
Object-oriented Programming in C#
Introduction to C#
Commands and Control Structures

On this page we discuss control structures for selection and iteration. As usual, we concentrate on the differences between C an C#.

Almost all control structures in C can be used the same way in C#

  • Similarities

    • Expression statements, such as a = a + 5;

    • Blocks, such as {a = 5; b = a;}

    • if, if-else, switch, for, while, do-while, return, break, continue, and goto in C# are all similar to C

  • Differences

    • The C# foreach loop provides for easy traversal of all elements in a collection

    • try-catch-finally and throw in C# are related to exception handling

    • Some more specialized statements have been added: checked, unchecked, using, lock and yield.

/user/normark/oop-csharp-1/sources/c-sharp/introductory-examples/definite-assignment/definite-assignment.csDemonstrations of definite assignment. This program is explained


/user/normark/oop-csharp-1/sources/c-sharp/introductory-examples/control-structures/if-demo.csDemonstrations of if. This program is explained


/user/normark/oop-csharp-1/sources/c-sharp/introductory-examples/control-structures/switch-demo.csDemonstrations of switch. This program is explained


/user/normark/oop-csharp-1/sources/c-sharp/introductory-examples/control-structures/foreach-demo.csDemonstrations of foreach.


/user/normark/oop-csharp-1/sources/c-sharp/introductory-examples/control-structures/try-catch-demo.csDemonstrations of try catch. This program is explained