Wrox Programmer Forums
|
BOOK: MCSD Certification Toolkit (Exam 70-483): Programming in C#
This is the forum to discuss the Wrox book MCSD Certification Toolkit (Exam 70-483): Programming in C# by Tiberiu Covaci, Rod Stephens, Vincent Varallo, Gerry O'Brien; ISBN: 978-1-118-61209-5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: MCSD Certification Toolkit (Exam 70-483): Programming in C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 28th, 2015, 05:46 PM
Registered User
 
Join Date: Mar 2015
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
Default Chapter 3, Page 92 - Extension Methods Typo

On my book it's stated:

" Extension methods can be applied to your own types or even existing types in .NET. An example might be adding some functionality to the Math class that .NET already includes. "

I failed every attempt I shot for in extending methods to that class. I've done some research now and I found out that Extension Methods can't be added to static classes such as System.Math. So is that a typo or there's a solution of some sort?

Thank you for your help.
 
Old March 28th, 2015, 11:29 PM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Sorry, I think you're right about that. I can't figure out how to add an extension method to System.Math either.

You cannot create an instance of a static class, so you can't use one as a parameter when building the extension method.

Static classes are also sealed, so you can't inherit from them. That paragraph says you don't need to inherit from the Math class, which sort of also implies that you might want to do that, but it's not allowed.

Interestingly (at least I think it's sort of interesting) you can extend a sealed class (such as int), but not a static one.

I think that paragraph was badly worded. The paragraph goes on to say that it won't add an extension method to the Math class, but instead will extend the int type. That *is* possible.

I think what the author meant was that you can add functionality as if it were provided by the Math class, in this example by extending int.

Sorry about the confusion.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
The Following User Says Thank You to Rod Stephens For This Useful Post:
jack_johnson (March 29th, 2015)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Typo, Chapter 20 page 416 eightbits2011 BOOK: Visual Basic 2008 Programmer's Reference ISBN: 978-0-470-18262-8 3 December 16th, 2011 07:15 PM
Extension methods and testing MrFixxiT BOOK: Professional ASP.NET Design Patterns 2 April 14th, 2011 05:37 AM
Setting the Master page hoses site... Page 92... richv BOOK: Beginning SharePoint 2010 Development 19 December 30th, 2010 10:21 AM
Extension methods vs inheritance perstam C# 2008 aka C# 3.0 3 March 2nd, 2010 06:35 PM
Chapter 1, page 11 typo? tumana BOOK Beginning Linux Programming, 3rd Edition 4 August 25th, 2006 10:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.