How to Clamp Player Movement ?

Hello, I am new to Unity Scripting.i dont know how to clamp player position on Y axis. I searched for more tutorial on Youtube, but nothing clears my question. Please give me line of code to clamp the player position on y axis from 45f to 300f. Thanks in advance
`using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Movement : MonoBehaviour
{
public float speed;
public float minSpeed;
public float maxSpeed;
public float rotSpeed1;
public float rotSpeed2;
public float minY = 45f;
public float maxY = 200f;

void Start()
{
    
}

void Update()
{
    transform.position += transform.forward * Time.deltaTime * speed;
   
    if (Input.GetKey(KeyCode.LeftArrow))
    {
        transform.Translate(Vector3.left * rotSpeed1 * Time.deltaTime);
    }

    if (Input.GetKey(KeyCode.RightArrow))
    {
        transform.Translate(Vector3.right * rotSpeed1 * Time.deltaTime);
    }

    if (Input.GetKey(KeyCode.UpArrow))
    {
        transform.Translate(Vector3.up * rotSpeed1 * Time.deltaTime);
    }

    if (Input.GetKey(KeyCode.DownArrow))
    {
        transform.Translate(Vector3.down * rotSpeed1 * Time.deltaTime);
    }
}

}`

transform.position = new Vector3(transform.position.x, Mathf.Clamp(transform.position.y, 45, 300), transform.position.z);