gameObject.collider2D.enabled is not working

public void Kill()
_controller.HandleCollisions = false;
gameObject.collider2D.enabled = false;
IsDead = true;


Error: Assets/Scripts/Player.cs(48,31): error CS1061: Type UnityEngine.Component' does not contain a definition for enabled’ and no extension method enabled' of type UnityEngine.Component’ could be found (are you missing a using directive or an assembly reference?)

How do I fix this?

I don’t think there’s a shorthand for Collider2D.
Use this:

this.gameObject.GetComponent<Collider2D>().enabled = false;

I must get the component first.
Try something like this:

gameObject.GetComponent<Collider2D>().enabled = false;

Try this:

Collider2D _col = GetComponent<Collider2D>();
_col.enabled = false;