Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2012/5.0 > BOOK: MCSD Certification Toolkit (Exam 70-483): Programming in C#
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 28th, 2015, 06:46 PM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
Reply With Quote
  #2 (permalink)  
Old March 29th, 2015, 12:29 AM
Rod Stephens's Avatar
Wrox Author
Points: 3,145, Level: 23
Points: 3,145, Level: 23 Points: 3,145, Level: 23 Points: 3,145, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 641
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!)
Reply With Quote
The Following User Says Thank You to Rod Stephens For This Useful Post:
jack_johnson (March 29th, 2015)
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 06: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 11:43 AM



All times are GMT -4. The time now is 04:15 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.