How do I change the box collider 2D size in a c# script?

I am a beginner with scripting and unity and am trying to create a 2D game. I fallowed the 2D Character Controllers tutorial video and my player is able to move back and forth and also jumps. I also have it set where when I press “z” he ducks. I was wondering if it was possible to also change the box collider 2D size so the player could fit in smaller places.

 GetComponent<BoxCollider2D>().size = new Vector2(1f, 0.5f);