Getting ready

We will be using an often used method to test if a value is of a specific type. Yes, you guessed it, we're going to be using TryParse. I can already hear some of you groan (or is it just me?). Using TryParse is (for me anyway) such a bittersweet thing to do. It's great being able to try and parse something to test if it is valid, but the use of the out variable was never as neat and tidy as I would have liked. If you are not familiar with the TryParse method, it is a method that tests to see if a value parses to a specific type. If it does, TryParse will return a Boolean value of true ; otherwise, it will return false.

Get C# 7 and .NET Core Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.