-1

I don't know if this is a good or bad idea, or if it's technically even possible... but I'd like to have something of the following sort:

public class Math {
  public int gcd(a,b) // Method for Greatest Common Denominator
  public int lcm(a,b) // Method for Least Common Multiple
  public int factorial(a) // Method for factorial
  ...
}

and then I'd also like to have a namespace called Math that has subclasses such as Math.Matrix, Math.RowVector, Math.ColumnVector, etc... so I can define my own Matrix data structure and its associated actions.

Is this advisable? I am not too keen on the idea of using some other name for my Math class, as I want it to be a static class with all sorts of functions/methods that are useful to me, and at the same time, I want to gather all my relevant data structures under a Math namespace.

0
5

See these for a clarification: Do not name a class the same as its namespace and Names of Namespaces

Basically,

DO NOT use the same name for a namespace and a type in that namespace.

I would use something like MathUtilities or MathUtil, for short, for the namespace and then you can have your MathUtil.Math and the rest.

0

Is it technically possible? Try it and find out, at worst the compiler will yell at you, but won't call you nasty names.

What you are trying to do is make a "Utils" or similar class that should be in your Math namespace. Generally though "Utils" class is frowned upon but still well understood if you use it. In that case you can break them up into disciplines like Math.Trig or Math.Geometry.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.