Book Image

Programming in C#: Exam 70-483 (MCSD) Guide

By : Simaranjit Singh Bhalla, SrinivasMadhav Gorthi
Book Image

Programming in C#: Exam 70-483 (MCSD) Guide

By: Simaranjit Singh Bhalla, SrinivasMadhav Gorthi

Overview of this book

Programming in C# is a certification from Microsoft that measures the ability of developers to use the power of C# in decision making and creating business logic. This book is a certification guide that equips you with the skills that you need to crack this exam and promote your problem-solving acumen with C#. The book has been designed as preparation material for the Microsoft specialization exam in C#. It contains examples spanning the main focus areas of the certification exam, such as debugging and securing applications, and managing an application's code base, among others. This book will be full of scenarios that demand decision-making skills and require a thorough knowledge of C# concepts. You will learn how to develop business logic for your application types in C#. This book is exam-oriented, considering all the patterns for Microsoft certifications and practical solutions to challenges from Microsoft-certified authors. By the time you've finished this book, you will have had sufficient practice solving real-world application development problems with C# and will be able to carry your newly-learned skills to crack the Microsoft certification exam to level up your career.
Table of Contents (22 chapters)
17
Mock Test 1
18
Mock Test 2
19
Mock Test 3

Variance in delegates

C# supports variance in delegate types with matching method signatures. This feature was introduced in .NET Framework 3.5. This means delegates can now be assigned with matching signatures but also that methods can return derived types.

If a method has a return type derived from the one defined in a delegate, it is defined as covariance in delegates. Similarly, if a method has fewer derived parameter types than those defined in a delegate, it is defined as contravariance.

Let's look at an example to understand covariance. For the purpose of this example, we will create a few classes.

Here, we will create the ParentReturnClass, Child1ReturnClass, and Child2Return classes. Each of these has a string type property. Both child classes are inherited from ParentReturnClass:

internal class ParentReturnClass
{
public string Message { get; set; }
}

internal class...