Book Image

Functional C#

Book Image

Functional C#

Overview of this book

Functional programming makes your application faster, improves performance, and increases your productivity. C# code is written at a higher level of abstraction, so that code will be closer to business requirements, abstracting away many low-level implementation details. This book bridges the language gap for C# developers by showing you how to create and consume functional constructs in C#. We also bridge the domain gap by showing how functional constructs can be applied in business scenarios. We’ll take you through lambda expressions and extension methods, and help you develop a deep understanding of the concepts and practices of LINQ and recursion in C#. By the end of the book, you will be able to write code using the best approach and will be able to perform unit testing in functional programming, changing how you write your applications and revolutionizing your projects.
Table of Contents (19 chapters)
Functional C#
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Getting closer to extension methods


An extension method is a capability that can extend the ability of an existing class or type without making any modification to the existing class or type. This means that an extension method enables us to add methods to the existing class or type without having to either create a new derived type or recompile.

Extension methods were introduced in C# 3.0 and can be applied to our own types or existing types in .NET. The extension method will be used a lot in functional programming since it suits the method chaining concept, which we have already used in Chapter 1, Tasting Functional Style in C#, when refactoring code in a functional style.

Creating an extension method

Extension methods have to be declared in a static, nongeneric, and non-nested class. They are a static method inside a static class. To create an extension method, first we have to create a public static class since the extension methods have to be included in the static class. After the public...