Lecture overview -- Keyboard shortcut: 'u'  Previous page: Examples of mutable structs in C# -- Keyboard shortcut: 'p'  Next page: Boxing and Unboxing -- 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 : 29
Object-oriented Programming in C#
Reference types, Value types, and Patterns
Examples of immutable structs in C#

Immutable structs fits nicely with value semantics. This is illustrated with the continuation of the example from the previous page.

An example of immutable points in C# and functional programming style

/user/normark/oop-csharp-1/sources/c-sharp/point/struct-immutable/Point.csThe struct Point - immutable.


/user/normark/oop-csharp-1/sources/c-sharp/point/struct-immutable/Client.csApplication the struct Point - immutable.


/user/normark/oop-csharp-1/sources/c-sharp/point/struct-immutable/outputOutput from the application.


There is a misfit between mutable datatypes and use of value semantics

It is recommended to use structs in C# together with a functional programming style

Go to exerciseAre playing cards and dice immutable?