How to create a grid system

Im making a game where you click and drag little areas to assign them to build buildings. How would you make a grid that would go with that. I don’t know where to start and I code in c#

It’s actually quite simple. You just have to clamp certain values.

        public int GridSpacing = 1;
        void Update()
        {
            transform.position = SnapToGrid(transform,GridSpacing);
        }
        Vector3 SnapToGrid(Transform obj, int gridSnap)
        {
            Vector3 pos = obj.transform.position;
            Vector3 snapHits = new Vector3(Mathf.Round(pos.x / gridSnap) * gridSnap, pos.y, Mathf.Round(pos.z / gridSnap) * gridSnap);
            Vector3 snapTransform = new Vector3(snapHits.x - (obj.transform.localScale.x / 2.0F), pos.y, snapHits.z - (obj.transform.localScale.z / 2.0F));
            pos = snapTransform;
            return pos;
        }