Category Archive for: Operators and Casts

User-Defined Casts

Earlier in this chapter, you learned that you can convert values between predefined data types through a process of casting. You also saw that C# allows two different types of casts: implicit and explicit. This section looks at these types of casts. For an explicit cast, you explicitly mark the cast in your code by writing the…

Read More →

Operator Overloading

This section looks at another type of member that you can define for a class or a struct: the operator overload. Operator overloading is something that will be familiar to C++ developers. However, because the concept will be new to both Java and Visual Basic developers, we explain it here. C++ developers will probably prefer to skip…

Read More →

Comparing Objects for Equality

After discussing operators and briefly touching on the equality operator, it is worth considering for a moment what equality means when dealing with instances of classes and structs. Understanding the mechanics of object equality is essential for programming logical expressions and is important when implementing operator overloads and casts, which is the topic of the rest of this…

Read More →

Type Safety

Strong typing enables many of the services provided by .NET,including security and language interoperability. As you would expect from a language compiled into IL, 0# is also strongly typed. Among other things, this means that data types are not always seamlessly interchangeable. This section looks at conversions between primitive types. C# also supports conversions between different reference types…

Read More →


Although most of C#’s operators should be familiar to C and C++ developers, this section discusses the most important operators for the benefit of new programmers and Visual Basic converts, as.well as to shed light on some of the changes introduced with C# . C# supports the operators listed in the following table, Img Note that four…

Read More →

Operators and Casts

The preceding chapters have covered most of what you need to start writing useful programs using C#. This chapter completes the discussion of the essential language elements and begins to illustrate some powerful aspects of C# that allow you to extend the capabilities of the C# language. Specifically, this chapter discusses the following: The operators available in…

Read More →

Back to Top