So far in this series we have discussed the robust type system in C# and what kinds of primitive types can exist.
Sometimes we want to take an object and change its type; for example, take a value that was an
int and change it to a
double, or take a
float and turn it into a
long. We can do this in two ways: casting and conversion.
We can also take objects of type
string and attempt to change their value into a different type through parsing.
Project for this post: 3CastingAndConversion
Casting is taking an object and attempting to "force" it to change types. When a cast is attempted, if the value of the object is allowable in the new type, the object will be casted into an object of the specified type.
We cast a value by placing the targeted type in parentheses
() next to the value we want to cast.
C#'s compiler allows many different kinds of casting. For example, we can cast an
int to a
char to an
int, or a
float to a
Let's continue our C# in Simple Terms series with one of the basic parts of any line of code: the operators.
Now that we understand a little more about classes and previously learned the difference between value types and reference types, it's time to explore some more specialized C# types. In today's edition of C# in Simple Terms, let's explore two useful value types: structs and enums.
In the past, we have used mega-series to tackle big subjects such as design patterns, anti-patterns, and sorting algorithms. In this series, we're going back to basics to discover, learn, and teach the programming language we all know and love: C#!
In this article, the latest of our C# in Simple Terms series, we're going to discuss how to control the flow of execution in a C# program. This means we will answer the question, "how does the code know what to do next?"
C/C++ problems. If you are familiar with C/C++then you must have come across some unusual things and if you haven’t, then you are about to. The below codes are checked twice before adding, so feel free to share this article with your friends.