Improving your C# Skills
eBook - ePub

Improving your C# Skills

Solve modern challenges with functional programming and test-driven techniques of C#

  1. 606 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Improving your C# Skills

Solve modern challenges with functional programming and test-driven techniques of C#

About this book

Conquer complex and interesting programming challenges by building robust and concurrent applications with caches, cryptography, and parallel programming.

Key Features

  • Understand how to use.NET frameworks like the Task Parallel Library (TPL)and CryptoAPI
  • Develop a containerized application based on microservices architecture
  • Gain insights into memory management techniques in.NET Core

Book Description

This Learning Path shows you how to create high performing applications and solve programming challenges using a wide range of C# features. You'll begin by learning how to identify the bottlenecks in writing programs, highlight common performance pitfalls, and apply strategies to detect and resolve these issues early. You'll also study the importance of micro-services architecture for building fast applications and implementing resiliency and security in.NET Core. Then, you'll study the importance of defining and testing boundaries, abstracting away third-party code, and working with different types of test double, such as spies, mocks, and fakes. In addition to describing programming trade-offs, this Learning Path will also help you build a useful toolkit of techniques, including value caching, statistical analysis, and geometric algorithms. This Learning Path includes content from the following Packt products:

  • C# 7 and.NET Core 2.0 High Performance by Ovais Mehboob Ahmed Khan
  • Practical Test-Driven Development using C# 7 by John Callaway, Clayton Hunt
  • The Modern C# Challenge by Rod Stephens

What you will learn

  • Measure application performance using BenchmarkDotNet
  • Leverage the Task Parallel Library (TPL) and Parallel Language Integrated Query (PLINQ)library to perform asynchronous operations
  • Modify a legacy application to make it testable
  • Use LINQ and PLINQ to search directories for files matching patterns
  • Find areas of polygons using geometric operations
  • Randomize arrays and lists with extension methods
  • Use cryptographic techniques to encrypt and decrypt strings and files

Who this book is for

If you want to improve the speed of your code and optimize the performance of your applications, or are simply looking for a practical resource on test driven development, this is the ideal Learning Path for you. Some familiarity with C# and.NET will be beneficial.

Trusted by 375,005 students

Access to over 1 million titles for a fair monthly price.

Study more efficiently using our study tools.

Information

Year
2019
Print ISBN
9781838558383
Edition
1
eBook ISBN
9781838550318

Geometry

This chapter includes geometric problems. Some ask you to calculate values such as π or the area below a curve. Others demonstrate useful techniques such as Monte Carlo algorithms. Finally, some are directly useful if you need to perform geometric operations such as drawing arrowheads or finding intersections between line segments.
Many of these problems have intuitive graphical purposes. In those cases, the solutions may include graphical components that draw the problem and its solution. The graphics code usually isn't necessary to solve the problems, however; it just makes visualizing the solution easier, so I won't describe that code in detail. Download the solutions to see all of the details.

Problems

Use the following problems to test your geometric programming skills. Give each problem a try before you turn to the solutions and download the example programs. If you have trouble with the graphical part, try to implement the non-graphical pieces. Then, you can download the example solutions and replace the key parts of the program with your code.

1. Monte Carlo π

A Monte Carlo algorithm uses randomness to approximate the solution to a problem. Often, using more random samples gives you a more accurate approximated solution or gives a greater probability that the solution is correct.
For this problem, use a Monte Carlo algorithm to approximate π. To do that, generate random points in the square (0 ≤ X, Y ≤ 1) and then see how many fall within a circle centered in that square.

2. Newton's π

Various mathematicians have developed many different ways to approximate π over the years. Sir Isaac Newton devised the following formula to calculate π:
Use Newton's method to approximate π. Let the user enter the number of terms to calculate. Display the approximation and its error.
How does this value compare to the fraction 355/113? Do you need to use checked blocks to protect the code?

3. Bisection root-finding

Root-finding algorithms find values (y) for which an equation y = F(x) equals zero. For example, the equation y = x2 – 4 has roots at x = 2 and x = -2 because at those values y = 0.
To find roots using binary subdivision, the program starts with an interval, x0 ≤ x ≤ x1, which we suspect contains a root. For the method to work, F(x0) and F(x1) must have different signs. In other words, one must be greater than zero and one must be less than zero.
To look for the root, the method picks the middle X value, xnew = (x0 + x1) / 2, and then calculates F(xnew). If the result is greater than zero, then you know that the root lies between xnew and whichever of x0 and x1 gives a value less than zero.
Similarly, if the result is less than zero, you know that the root lies between xnew and whichever of x0 and x1, whichever gives a value greater than zero.
Now, you update x0 and x1 to bound the new interval. You then repeat the process until F(x0) and F(x1) are within some maximum allowed error value.
Write a program that uses binary subdivision to find roots for equations. Make the equation a delegate parameter to the main method so you can easily pass the method different equations. Use the program to find the roots for the following equations:
For extra credit, make the program draw the equations and their roots.

4. Newton's method

Binary subdivision uses intervals to quickly converge on an equation's root. Newton's method, which is also called the Newton-Raphson method, uses a different technique to converge even more quickly.
The method starts with a value (x). As long as F(x) is not close enough to zero, the method uses the derivative of the function to find the slope F'(x). It then follows the tangent line at that point to the new point x' where the line intersects the X axis. The value x' becomes the method's next guess for the root. The program continues calculating new values until F(x) is close enough to 0.
Finding the point of intersection between the tangent line and the X axis is easier than you might think. If you start with the value xi, you simply use the following equation to find the next value, xi+1:
Here, F is the function and F' is its derivative.
Write a program that uses Newton's method to find roots for equations. Make the equation and its derivative delegate parameters to the main method so you can easily pass different equations to the met...

Table of contents

  1. Title Page
  2. Copyright and Credits
  3. About Packt
  4. Contributors
  5. Preface
  6. What's New in .NET Core 2 and C# 7?
  7. Understanding .NET Core Internals and Measuring Performance
  8. Multithreading and Asynchronous Programming in .NET Core
  9. Securing and Implementing Resilience in .NET Core Applications
  10. Why TDD is Important
  11. Setting Up the .NET Test Environment
  12. Setting Up a JavaScript Environment
  13. What to Know Before Getting Started
  14. Tabula Rasa – Approaching an Application with TDD in Mind
  15. Testing JavaScript Applications
  16. Exploring Integrations
  17. Changes in Requirements
  18. The Legacy Problem
  19. Unraveling a Mess
  20. Geometry
  21. Randomization
  22. Files and Directories
  23. Advanced C# and .NET Features
  24. Cryptography
  25. Other Books You May Enjoy

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn how to download books offline
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 990+ topics, we’ve got you covered! Learn about our mission
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more about Read Aloud
Yes! You can use the Perlego app on both iOS and Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app
Yes, you can access Improving your C# Skills by Ovais Mehboob Ahmed Khan, John Callaway, Clayton Hunt, Rod Stephens in PDF and/or ePUB format, as well as other popular books in Computer Science & Cryptography. We have over one million books available in our catalogue for you to explore.