academyzaribacom 1 Lecture Content BunniesVersusZombies Code Review Namespaces Structures Generics indexers and operator overloading 2 1 Code Review 3 Bunnies Zombies 2 Namespaces ID: 760466
Download Presentation The PPT/PDF document "2.2 Defining Classes Part 2" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
2.2 Defining Classes Part 2
academy.zariba.com
1
Slide2Lecture Content
BunniesVersusZombies Code ReviewNamespacesStructuresGenerics, indexers and operator overloading
2
Slide31. Code Review
3
Bunnies
Zombies
Slide42
. Namespaces
4
Bunnies
Zombies
Slide53. Structures
5
What is a structure in C#?
Unlike classes, structures are value types.
Structures behave like primitive types (
int
, double…)
Structures can have properties, methods, fields, constructors, events, etc.
Mostly used to store data (fields), e.g. points in 2D, 3D space
Slide64. Generics, indexers andoperator overloading
6
Homework
7
Organize your previous homework into separate files, namespaces and folders. Decouple your classes with the Console. Fix all
StyleCop
errors that arise.
Create a class Fraction with the properties/fields numerator,
denominator, value
(string which will return for example “1/2”) and decimal value (e.g. “0.5”). Perform the necessary validations when creating a new Fraction. Overload the operators “+”, “-”, “*”, “/”. Test your application with different calculations.
Create a class Matrix which corresponds to the mathematical definition of a matrix. Overload the operators “+”, “-” and “*”. Check if those operations can be performed at all (validation). Test all of your operations.
Create your own Generic List (called
myList
). Implement the following: Accessing by index, removing element by index, inserting element at a given position, adding an element to the list, clearing the list, finding element by value and
ToString
().
Slide88
References
Slide99
Zariba Academy
Questions