© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2022
G. ByrneTarget C#https://doi.org/10.1007/978-1-4842-8619-7_7

7. Casting and Parsing

Gerard Byrne1  
(1)
Belfast, Ireland
 

Data Types, Casting, and Parsing

We learned in Chapter 6 that we can declare variables with a data type and then assign values to them in our code. We learned that we can accept user input and assign the input value to a variable, and we saw that there are times when we will need to convert a variable from one data type to another. In this context we learned about narrowing and widening conversions, and we used a conversion from an int to a byte, which involved casting, for example, (byte).

In C#, casting is a method used to convert one data ...

Get Target C#: Simple Hands-On Programming with Visual Studio 2022 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.