C# creating an array that holds coordinate points

I am working on a C# script for use with unity that will act as a gravity organizer (my term). For this I want the script to locate all objects that have a mass (a float that will assigned) and store their Mass, and coordinates (X,Y) in an array. I am not sure how I would go about identifying the Mass of each object and then storing the coordinates. I think that I would need two scripts, one for keeping track of all the masses, coordinates, and calculating the force of gravity, and then one for holding each object’s mass and location.
Any help would be appreciated

C# is an object-oriented programming language. Object orientation was created specifically to solve the problem you are having.

Make a file with public class (NOT a MonoBehaviour script), and make have it hold all your variables. You can call it “EntityWithGravity”, and you can then use that class to create objects with the characteristics that you define within that class (can be variables, constants or even functions).

This way, you can effectively create an object which contains several characteristics, like float number representing its mass, some X and Y coordinates, a name, a favourite colour, his favourite saturday morning cartoon and a list of its worst fears - whatever you want!

You can then create an array that holds EntityWithGravity-type variables, and each position in the array contains one of those entities, with all the information you want, tidily organized.

This has huge ramifications and most engineers work with this during their entire degree in college, but at the simplest level, it can still help you a lot.

You can learn more about classes here: Classes | Microsoft Learn

Hope it helped!