Skip to content

dogaaydinn/CSharp-Covariance-Polymorphism-Exercises

Repository files navigation

Project Title: Understanding Advanced C# Concepts

About

In this project, I created various examples and applications to understand important concepts in the C# language. Below are the key topics covered in this project along with related questions:

  • Covariance and Contravariance: Concepts related to type conversion in generic types, such as the ability to convert a subclass to a superclass type.
  • Boxing and Unboxing: The process of converting value types to reference types and vice versa.
  • Polymorphism: How methods can be redefined in different classes.
  • Type Conversion: Methods of type conversion, including implicit (covert) and explicit (overt) conversions.
  • Generic Conversions: Conversion processes for generic types.
  • Delegate and Array: Usage and management of delegates and arrays.
  • Upcasting and Downcasting: Type conversion between parent and child types.
  • Assignment Compatibility: Compatibility of assignments between different types.

Project Structure

This project is structured as a console application containing various examples related to the above topics. Each section includes classes and interfaces designed to explain a specific concept.

Examples

  1. Polymorphism - Method Overriding: Demonstrates polymorphism using the Vehicle, Car, and Bike classes.
  2. Upcasting and Downcasting: Includes examples that examine conversions between the Car and Vehicle classes.
  3. Assignment Compatibility: Explains assignment compatibility between object and string types.
  4. Covariance and Contravariance: Provides examples of how to use generic interfaces.
  5. Explicit and Implicit Conversion: Presents examples of implicit and explicit conversion with a Temperature class that converts temperature units.

Conclusion

This project provides examples and applications that will help you understand complex concepts in the C# language. Explore how to use these concepts as you develop your code and deepen your understanding.

Usage

To run your project, follow these steps:

  1. Download or clone the project files.
  2. Open your C# development environment (e.g., Rider, Visual Studio or .NET CLI).
  3. Open the project file and run it.
git clone <repository-url>
cd <project-directory>
dotnet run