Category: C#

C# Compiler Warning – CS8847 the switch expression does not handle so

In this blog post, you’ll learn more about the C# Compiler Warning – CS8847 and the related message description C# Compiler Warning Code CS8847 C# Compiler Description for the Code :CS8847 The switch expression does not handle some null inputs (it is not exhaustive). For example, the pattern ‘{0}’ is not covered. However, a pattern with a ‘when’ clause might successfully match this value.

Error – The Windows Phone Emulator wasn’t able to create the virtual machine “Windows Phone 8 Emulator”

This was one of the errors that I received when trying to install the Windows Phone 8 SDK in my Windows 8.1 system and trying to create a new project and run it. The error message was “The Windows Phone Emulator wasn’t able to create the virtual machine, something happened while creating a switch”… The Windows Phone 8 emulator has the prerequisite that the system…

How to make a Type Sortable in C# using IComparable interface?

Assume that you have a type which would be stored in a List. You would want to use List.Sort method to sort your data in the List. For example , assume that you have to store objects of type Employee in List<Employee> and sort the List by Age using the Sort method. To do this , we can use he IComparable<T> interface. How to make…

C# Compiler Error – CS0191 a readonly field cannot be assigned to (

In this blog post, you’ll learn more about the C# Compiler Error – CS0191 and the related message description C# Compiler Error Code CS0191 C# Compiler Description for the Code :CS0191 A readonly field cannot be assigned to (except in a constructor or init-only setter of the type in which the field is defined or a variable initializer)

Example of Delegates in C#

Delegates in C# is simply a reference/pointer to a function . One of the typical usage of the delegates is the event handlers in .NET. Example of Delegates in C# Below is a sample code snippet demonstrating the usage of delegates to add and subtract 2 numbers.