[C#] Class reference

Hello !

I got a problem and I’m kinda plox ! I did a certain amount of code in C, and moving to a Object oriented code, C#, gives me some headhaches. Especially when it comes to code structure. I pretty much got the point about objects having parameters and methods. Which bug me is how to use generic code.

For example, let’s say the method Abs (absolute value) doesn’t exist and I want to create one. A lot of others scripts need it. What is the most proper way to make this method. So far I managed to have something working :

class TheTest
{
    public static float Abs2(float i)
    {
        if (i < 0)
            return -i;
        return i;
    }
}
//...
Debug.Log(TheTest.Abs2(-10));

Going further, I wonder if there is a better way, or if it’s possible to create a kind of “Library” that I can refer with using so I have those available in any projects ?

Thanks in advance !

For a method like Abs, it doesn’t make sense that you have to create an instance of of class. For those, you have the possibility to make the method static. And if you have a closer look, that’s what Unity is also doing:

Mathf is a class defined by Unity and they have the static method Abs. Static methods don’t require an instance, but can directly be called using the class name.

A lot of people have their own code libraries. It is a good practice to use your own namespace for that.

So I’m doing it right with static. Good to know.

Also I found this : Unity - Manual: Managed plug-ins

I guess I’m kinda good to go. Thanks ^^.

EDIT : Hups. Now this raise another problem. If my code do a reference to a namespace using DLL files, I build the game and share it as a Standalone Windows executable, what about the DLL? Will they be included in the game folder ?