Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
The Modern C# Challenge
The Modern C# Challenge

The Modern C# Challenge: Become an expert C# programmer by solving interesting programming problems

eBook
$24.99 $35.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

The Modern C# Challenge

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.

20. 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 ...

Solutions

20. Monte Carlo π

The following code uses a Monte Carlo algorithm to estimate π:

// Use Monte Carlo simulation to estimate pi.
private double MonteCarloPi(long numPoints)
{
Random rand = new Random();

// Make a bitmap to show points.
int wid = pointsPictureBox.ClientSize.Width;
int hgt = pointsPictureBox.ClientSize.Height;
Bitmap bm = new Bitmap(wid, hgt);
using (Graphics gr = Graphics.FromImage(bm))
{
gr.Clear(Color.White...
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Gain useful insights on advanced C# programming topics and APIs
  • Use locking and cached values to solve parallel problems
  • Take advantage of .NET's cryptographic tools to encrypt and decrypt strings

Description

C# is a multi-paradigm programming language. The Modern C# Challenge covers with aspects of the .NET Framework such as the Task Parallel Library (TPL) and CryptoAPI. It also encourages you to explore important programming trade-offs such as time versus space or simplicity. There may be many ways to solve a problem and there is often no single right way, but some solutions are definitely better than others. This book has combined these solutions to help you solve real-world problems with C#. In addition to describing programming trade-offs, The Modern C# Challenge will help you build a useful toolkit of techniques such as value caching, statistical analysis, and geometric algorithms. By the end of this book, you will have walked through challenges in C# and explored the .NET Framework in order to develop program logic for real-world applications.

Who is this book for?

The Modern C# Challenge is for all C# developers of different abilities wanting to solve real-world problems. There are problems for everyone at any level of expertise in C#

What you will learn

  • Perform statistical calculations such as finding the standard deviation
  • Find combinations and permutations
  • Search directories for files matching patterns using LINQ and PLINQ
  • Find areas of polygons using geometric operations
  • Randomize arrays and lists with extension methods
  • Explore the filesystem to find duplicate files
  • Simulate complex systems and implement equality in a class
  • Use cryptographic techniques to encrypt and decrypt strings and files

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 25, 2018
Length: 362 pages
Edition : 1st
Language : English
ISBN-13 : 9781789532630
Vendor :
Microsoft
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Oct 25, 2018
Length: 362 pages
Edition : 1st
Language : English
ISBN-13 : 9781789532630
Vendor :
Microsoft
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 136.97
The Modern C# Challenge
$43.99
Hands-On Neural Network Programming with C#
$43.99
Hands-On Microservices with C#
$48.99
Total $ 136.97 Stars icon
Banner background image

Table of Contents

10 Chapters
Mathematics Chevron down icon Chevron up icon
Geometry Chevron down icon Chevron up icon
Dates and Times Chevron down icon Chevron up icon
Randomization Chevron down icon Chevron up icon
Strings Chevron down icon Chevron up icon
Files and Directories Chevron down icon Chevron up icon
Advanced C# and .NET Features Chevron down icon Chevron up icon
Simulations Chevron down icon Chevron up icon
Cryptography Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.7
(3 Ratings)
5 star 66.7%
4 star 33.3%
3 star 0%
2 star 0%
1 star 0%
mkatiehaha Sep 26, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Helpful in sharpening my C# skills
Amazon Verified review Amazon
Clock End Gooner Oct 29, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I've just acquired this latest offering from Rod Stephens, and am absolutely delighted with it. The best description of this book's value I can offer is that for any developer with a solid grounding in C# will find a well organized complete and enjoyable set of coding katas. The set of programming exercises begins with implementing a class of LINQ Extension Methods based on mathematics, including Permutations, Combinations, Primality, and similar functions, working with basic .NET values such as DateTime values and string references, and later on, working with PLINQ and implementing simulations such as Conway's Game of Life, Dawkin's Weasel, as well as smaller graphically based simulations such as Space Force, an Asteroids based game, and Slingshot, using the Windows Forms classes for the graphics rendering.Each chapter for the range of .NET development topics covered are divided into Problems and Solutions, and as Stephens has done consistently over the years with his previous books and blog postings on his C# Helper website, are written in a very clear and concise manner.I would highly recommend this title to any developer who is looking to experiment and challenge their problem-solving skills and hone the edge on their C# coding skills.
Amazon Verified review Amazon
KRBOOKS Feb 21, 2019
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
This book assumes you have a working knowledge of C# with each chapter having a portion that describes the problem and a portion that describes the solution. This is the first book I have read like this and it was a fairly good experience. When I first sat down with the book I grabbed a notepad and pen and scribbled out some c# pseudo code to try and work the problems then flipped over to the solutions to see if I got it correct. A couple hours later I ran out of paper :). That may not be your preferred way of interacting with the book, however if you enjoy coding puzzles or are looking for a good way to expand your c# skills, this book will do a good job of sucking you in. If you want to use pen and paper, make sure you have plenty on hand.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.