Book Image

Learn C# in 7 days

By : Gaurav Aroraa
1 (1)
Book Image

Learn C# in 7 days

1 (1)
By: Gaurav Aroraa

Overview of this book

This book takes a unique approach to teach C# to absolute beginners. You’ll learn the basics of the language in seven days. It takes a practical approach to explain the important concepts that build the foundation of the C# programming language. The book begins by teaching you the basic fundamentals using real-world practical examples and gets you acquainted with C# programming. We cover some important features and nuances of the language in a hands-on way, helping you grasp the concepts in a fluid manner. Later, you’ll explore the concepts of Object-Oriented Programming (OOP) through a real-world example. Then we dive into advanced-level concepts such as generics and collections, and you’ll get acquainted with objects and LINQ. Towards the end, you’ll build an application that covers all the concepts explained in the book. By the end of this book, you will have next-level skills and a good knowledge of the fundamentals of C#.
Table of Contents (15 chapters)
Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Local functions


Local functions can be achievable using function and action using anonymous methods in prior versions, but there are still a few limitations:

  • Generics
  • ref and out parameters
  • params

Local functions are featured to declare within the block scope. These functions are very powerful and have the same capability as any other normal function but with the difference that they are scoped within the block these were declared.

Consider the following code-example:

public static string FindOddEvenBySingleNumber(int number) => IsOddNumber(number) ? "Odd" : "Even";

The method FindOddEvenBySingleNumber() in the preceding code is simply returning a number as Odd or Even for numbers greater than 1. This uses a private method, IsOddNumber(), as shown here:

private static bool IsOddNumber(int number) => number >= 1 && number % 2 != 0; 

The method IsOddNumber() is a private method and is available within the class it declared. Hence, its scope is within a class and not within a code block...