How do i replace a Mesh Filter??

Hello how do i replace a mesh filter on a cube via code(C#)??

You probably don’t want to replace the whole MeshFilter component but the Mesh assinged to it. Just Assing a new mesh to the MeshFilter.

GetComponent<MeshFilter>().sharedMesh = mesh;