Tag c switch case

C# Exceptions – Try..Catch

C# Exceptions When executing C# code, different errors can occur: coding errors made by the programmer, errors due to wrong input, or other unforeseeable things. When an error occurs, C# will normally stop and generate an error message. The technical…

C# Files

Working With Files The File class from the System.IO namespace, allows us to work with files: Example using System.IO; // include the System.IO namespace File.SomeFileMethod(); // use the file class with methods The File class has many useful methods for…

C# Enum

C# Enums An enum is a special “class” that represents a group of constants (unchangeable/read-only variables). To create an enum, use the enum keyword (instead of class or interface), and separate the enum items with a comma: Example enum Level…

C# Multiple Interfaces

Multiple Interfaces To implement multiple interfaces, separate them with a comma: Example interface IFirstInterface { void myMethod(); // interface method } interface ISecondInterface { void myOtherMethod(); // interface method } // Implement multiple interfaces class DemoClass : IFirstInterface, ISecondInterface {…

C# Interface

Interfaces Another way to achieve abstraction in C#, is with interfaces. An interface is a completely “abstract class“, which can only contain abstract methods and properties (with empty bodies): Example // interface interface Animal { void animalSound(); // interface method…

C# Abstraction

Abstract Classes and Methods Data abstraction is the process of hiding certain details and showing only essential information to the user. Abstraction can be achieved with either abstract classes or interfaces (which you will learn more about in the next…

C# Polymorphism

Polymorphism and Overriding Methods Polymorphism means “many forms”, and it occurs when we have many classes that are related to each other by inheritance. Like we specified in the previous chapter; Inheritance lets us inherit fields and methods from another…

C# Inheritance

Inheritance (Derived and Base Class) In C#, it is possible to inherit fields and methods from one class to another. We group the “inheritance concept” into two categories: Derived Class (child) – the class that inherits from another class Base…

C# Properties

Properties and Encapsulation Before we start to explain properties, you should have a basic understanding of “Encapsulation“. The meaning of Encapsulation, is to make sure that “sensitive” data is hidden from users. To achieve this, you must: declare fields/variables as…