2 Replies - 10910 Views - Last Post: 14 July 2017 - 06:49 PM

#1 CoolCell6  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 20-November 16

Here's some C# useful math code

Posted 26 November 2016 - 11:49 PM

I decided I like C# and converting my useful vb.net code to C# and decided to share my math codes I just converted to C#
I like to have handy.

If you have for useful math code you want to share please post them I would love to see it.

using System;

        public static float CircumferenceOfCircle(float Diameter) => Convert.ToSingle(Math.PI * Diameter);

        public static float AreaOfCircle(float Radius) => Convert.ToSingle(Math.PI * (Radius * Radius));
       
        public static float AreaOfCube(float Length) => (Length * Length) * Length;
        
        public static float AreaOfCuboid(float Length, float Height, float Depth) => (Length* Depth) * Height;

        public static float AreaOfCylinder(float Height, float Radius) => Convert.ToSingle((Math.PI * (Radius * Radius)) * Height);
        
        public static float AreaOfPrism(float Area_Of_End, float Length) => Area_Of_End * Length;
        
        public static float PercentageOf(float Number, float Percent) => (Number / 100) * Percent;
        
        public static float NumberAfterReduction(float Original, float Percent) => Original - ((Original / 100) * Percent);
        
        public static float NumberAfterIncrease(float Original, float Percent) => Original + ((Original / 100) * Percent);

        public static float Feet2Yards(float Feet) => Feet / 3;
        
        public static float Inches2Feet(float Inches) => Inches / 12;
        
        public static float Yards2Miles(float Yards) => Yards / 1760;

        public static float Ounces2Pounds(float Ounces) => Ounces / 16;
        
        public static float Pounds2Stones(float Pounds) => Pounds / 14;
        
        public static float Stones2Tons(float Stones) => Stones / 160;
        
        public static float Pints2Gallons(float Pints) => Pints / 8;
        
        public static float Cm2Inch(float Cm) => (float)(Cm / 2.54);
        
        public static float Km2Mile(float Km) => (float)(Km / 1.61);
        
        public static float Kg2Pound(float KG) => (float)(KG / 0.454);

        public static float Litre2Pint(float Litres) => (float)(Litres / 0.568);

        public static float Litres2Gallon(float Litres) => (float)(Litres / 4.55);

        public static float Miles2Km(float Miles) => (float)(Miles / 0.621);
   
        public static float Gallons2Litres(float Gallons) => (float)(Gallons / 0.22);
      
        public static float Pounds2Kg(float Pounds) => (float)(Pounds / 2.2);

This post has been edited by tlhIn`toq: 27 November 2016 - 02:09 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Here's some C# useful math code

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5830
  • View blog
  • Posts: 19,876
  • Joined: 05-May 12

Re: Here's some C# useful math code

Posted 27 November 2016 - 05:35 AM

You are following the .NET Framework naming conventions. Variables should be Camel cased, not Pascal cased. You should not use abbreviations.

For better API design, you should have preferred double instead of float for extra precision in case the callers need it.

I'm curious about the need to convert from VB.NET to C#. Each of the compiled .NET languages can call each other's assemblies.
Was This Post Helpful? 0
  • +
  • -

#3 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5830
  • View blog
  • Posts: 19,876
  • Joined: 05-May 12

Re: Here's some C# useful math code

Posted 14 July 2017 - 06:49 PM

And the formulas for the area of a cube, cuboid, prism, and cylinder look wrong. Those look like volumes to me.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1