Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to extend Math class

How to extend Math class

Scheduled Pinned Locked Moved C#
tutorialquestion
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chesnokov Yuriy
    wrote on last edited by
    #1

    How to add to it more functions and still use Math.SomeFunction() convention. Math class is static, that is sealed. Is it possible to use partial or any other mechanisms?

    chesnokov

    C L L P 4 Replies Last reply
    0
    • C Chesnokov Yuriy

      How to add to it more functions and still use Math.SomeFunction() convention. Math class is static, that is sealed. Is it possible to use partial or any other mechanisms?

      chesnokov

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Chesnokov Yuriy wrote:

      How to add to it more functions and still use Math.SomeFunction() convention. Math class is static, that is sealed. Is it possible to use partial or any other mechanisms?

      You can't. Create your own utility class for the additional functions.

      Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Follow up on hiring a software developer * Aarrgghh!! Accidentally pressing the Caps Lock key My website | blog

      1 Reply Last reply
      0
      • C Chesnokov Yuriy

        How to add to it more functions and still use Math.SomeFunction() convention. Math class is static, that is sealed. Is it possible to use partial or any other mechanisms?

        chesnokov

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        You can't add anything to a sealed class. With C# 3.0 however, which ships with Visual Studio 2008, you can use a technique called "extension methods" to certain datatypes.

        1 Reply Last reply
        0
        • C Chesnokov Yuriy

          How to add to it more functions and still use Math.SomeFunction() convention. Math class is static, that is sealed. Is it possible to use partial or any other mechanisms?

          chesnokov

          L Offline
          L Offline
          Leyu
          wrote on last edited by
          #4

          Use a utility class like this public static class AdvancedMath { //Only if you want to call the method from here //Or rewrite the signature of the methods/properties you want public static decimal Abs(decimal value) { return Math.Abs(value); } //add any additional methods/properties you may have public static double MySpecialMethod(double value) { //do your special processing and return the result } }

          1 Reply Last reply
          0
          • C Chesnokov Yuriy

            How to add to it more functions and still use Math.SomeFunction() convention. Math class is static, that is sealed. Is it possible to use partial or any other mechanisms?

            chesnokov

            P Offline
            P Offline
            Paul Conrad
            wrote on last edited by
            #5

            Just create your own math class.

            "The clue train passed his station without stopping." - John Simmons / outlaw programmer

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups