Raycast pickup

I want to pickup items in an fps. But i just found code for that in javascript and in C# is this code not working.

if(Physics.Raycast(position, direction, hit, distance)
{
		
}

Why is this code not working in C# and how can i fix this?

Try this:

RaycastHit hit;
if(Physics.Raycast(position, direction, out hit, distance)
{        

}

In C# you need to put the “out” keyword before parameters like “hit” that receive a value from the function instead of passing one to the function.