Is it possible to call a variable in OnCollisionEnter2D

When using the following:

void OnCollisionEnter2D(Collision2D newCollision) {
	//method stuff here
}

Is it possible to declare a variable of type Collision2D outside of the function, then call it within the function? I only ask as i’ve tried it and I get error CS1041: Identifier expected, but I’m trying to determine if its just me missing something out or if its just not legal C# formatting.

So basically, instead of the above, have…

public Collision2D newCollision;

void OnCollisionEnter2D(newCollision) {
	//method stuff here
}

You can not do that.

The parameters need to be new variables. What you could do is:

public Collision2D newCollision;
 
void OnCollisionEnter2D(Collision2d p_newCollision) {
    newCollision = p_newCollision;
}