Add mesh collider to procedurally generated terrain

Can anybody help me add a collider to this code which generates terrain at runtime?

[RequireComponent(typeof(MeshFilter))]
public class MeshGenerator : MonoBehaviour
{

Mesh mesh;

Vector3[ ] vertices;
int[ ] triangles;

public int xSize = 100;
public int zSize = 100;

// Start is called before the first frame update
void Start()
{
mesh = new Mesh();
GetComponent().mesh = mesh;

CreateShape();
UpdateMesh();
}

void CreateShape()
{
vertices = new Vector3[(xSize + 1) * (zSize + 1)];

for (int i = 0, z = 0; z <= zSize; z++)
{
for (int x = 0; x <= xSize; x++)
{
float y = Mathf.PerlinNoise(x * .3f, z * .3f) * 2f;
vertices = new Vector3(x, y, z);
i++;
}
}
triangles = new int[xSize * zSize * 6];
int vert = 0;
int tris = 0;
for (int z = 0; z < zSize; z++)
{
for (int x = 0; x < xSize; x++)
{
triangles[tris + 0] = vert + 0;
triangles[tris + 1] = vert + xSize + 1;
triangles[tris + 2] = vert + 1;
triangles[tris + 3] = vert + 1;
triangles[tris + 4] = vert + xSize + 1;
triangles[tris + 5] = vert + xSize + 2;
vert++;
tris += 6;
}
vert++;
}
}
// UpdateMesh is called once per frame
void UpdateMesh()
{
mesh.Clear();
mesh.vertices = vertices;
mesh.triangles = triangles;
mesh.RecalculateNormals();
}
}

Try:

gameObject.AddComponent<MeshCollider>().mesh = mesh;

Thanks for the suggestion, when i tried it i got this error

Assets\Terrain\MeshGenerator.cs(22,49): error CS1061: 'MeshCollider' does not contain a definition for 'mesh' and no accessible extension method 'mesh' accepting a first argument of type 'MeshCollider' could be found (are you missing a using directive or an assembly reference?)

Yes, that was off the top of my head, to give you push in the right direction. You're meant to go look up the relevant classes and figure out the details. In this case the only relevant class is this one.

I think you already figured it out but just addgameObject.AddComponent<MeshCollider>().sharedmesh = mesh; at the end of UpdateMesh()