SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: extend methodes

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2010
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question extend methodes

    Hi I am trying to create extend methodes for math class by adding a couple of Trigonometric formula I just want to see if I am in the right track or not
    thank you
    Code:
    static class Trigonometric
        {
            private double m_hypotenuse_C;
            private double m_side1_A;
            private double m_side2_B;
    
    
    
    
            public Trigonometric()
            {
                // TODO: Complete member initialization
            }
    
            public Trigonometric(double side1, double side2)
            {
                m_side1_A = side1;
                m_side2_B = side2;
            }
    
            public Trigonometric(double hypotenuse, double side1_a, double side2_b)
            {
                m_hypotenuse_C = hypotenuse;
                m_side1_A = side1_a;
                m_side2_B = side2_b;
            }
    
    
    
            public double GetHypotenuse()
            {
                double side1 = Math.Pow(m_side1_A, 2);
                double side2 = Math.Pow(m_side2_B, 2);
    
                double totalOFsides = side1 + side2;
    
                return Math.Sqrt(totalOFsides);
            }
    
    
            static  double GetTriangleSide()
            {
                double hypotenuse = Math.Pow(m_hypotenuse_C, 2);
    
                double side = Math.Pow(m_side1_A, 2);
              
                double value = hypotenuse - side;
    
                return Math.Sqrt(value);
            }
    
    
            static  double GetTheta()
            {
                double theta;
                double result = m_side2_B / m_hypotenuse_C;
                return theta = Math.Asin(result);
       
                  
    
    
               
            }
            
        }

  2. #2
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,633
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    You don't really need extension methods here, you need to use both the public and the static keywords on your methods. Static classes cannot have instance (non-static) members.

  3. #3
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For Math it seems to be impossible to create extensions. It is possible only for non-static types, which allow to create objects.

    Code:
    public static class Extensions
    {
      public static double MyExtension(this string str, int arg)
      {
        ... put your logic here ...
      }
    }
    Make sure that you create a public static method in a public static class.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •