freeze rotation in code c#

C#
GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation;
Source

Also in C#: