How do I use a variable string as the stateName for the animator.Play() function?

I want to do the following :

public void ChangeAnimTo(string animStateName)
{
_animator.play(animStateName)
}

The issue with this is that the Play function needs a string to be put in quotations so it doesn’t accept
.Play(string) and only accepts .Play(“string”)

But if I use .Play(“aimStateName”) it takes this literally as the stateName and a not a parameter wich
changes itself to whatever string I put into the ChangeAnimTo() function.

I wanted to make a helper function wich inserts " at the beginning and end of the string and uses that for the play function but that obviously also doesn’t work because you cant insert a string thats string str1= " " ".

how can i make the play function take a undefined string?
or do I have to manually call the play function for every single animation state change?

If you want the animation to use the name of a variable as the string passed to Animation.Play(string), then try the nameof expression. Like this:

public void PlayNameOf(object theObject)
{
    Animation.Play(nameof(theObject));
}