Skip to Main Content
Pro C# 2010 and the .NET 4 Platform, Fifth Edition
book

Pro C# 2010 and the .NET 4 Platform, Fifth Edition

by Andrew Troelsen
May 2010
Intermediate to advanced content levelIntermediate to advanced
1752 pages
41h 17m
English
Apress
Content preview from Pro C# 2010 and the .NET 4 Platform, Fifth Edition

12.2. Understanding Operator Overloading

C#, like any programming language, has a canned set of tokens that are used to perform basic operations on intrinsic types. For example, you know that the + operator can be applied to two integers in order to yield a larger integer:

// The + operator with ints.
int a = 100;
int b = 240;
int c = a + b;  // c is now 340

Once again, this is no major newsflash, but have you ever stopped and noticed how the same + operator can be applied to most intrinsic C# data types? For example, consider this code:

// + operator with strings.
string s1 = "Hello";
string s2 = " world!";
string s3 = s1 + s2;  // s3 is now "Hello world!"

In essence, the + operator functions in specific ways based on the supplied data types ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Professional C# 5.0 and .NET 4.5.1

Professional C# 5.0 and .NET 4.5.1

Christian Nagel, Jay Glynn, Morgan Skinner
Visual C++ 2008: How to Program, Second Edition

Visual C++ 2008: How to Program, Second Edition

P. J. Deitel, H. M. Deitel, D. T. Quirk

Publisher Resources

ISBN: 9781430225492Purchase book