How do I call Nav Mesh agent Stop

error CS0120: An object reference is required to access non-static member `UnityEngine.NavMeshAgent.Stop()’

I have a enemy ai using a nav mesh agent . I need to call a nav mesh agent stop . So I can stop the enemy ai from sliding toward the player. I check the unity3d docs. Did the code and it didn’t work it gave me an error :

Here is my code :

NavMeshAgent.Stop();

You need an object reference

NavMeshAgent agent = GetComponent<NavMeshAgent>();
agent.Stop();

agent is the object reference. This assumes NavMeshAgent is on the same GameObject as the code.