Question: I'm pretty new to coding and always used "classname instancename=new classname()" to create instances but today I've found the following code which doesn't follow and won't work with this syntax. My question is what happens in the 5th line. Thank you very much.

```
private void _InsertIntoBinarySearchTree(ref Element<K> p , K key)
{
    if (p == null)
    {
        p = new Element<K>();//what happens here?
        p.key = key;
    }
    else
    {
        if (p.key.CompareTo(key) > 0)
        {
            _InsertIntoBinarySearchTree(ref p.left, key);
        }
        else if (p.key.CompareTo(key) < 0)
        {
            _InsertIntoBinarySearchTree(ref p.right, key);
        }
        else
        {
            throw new Exception("");
        }
    }
}

```

Answer: 
First, you can't use a type specifier for the variable `p` since you're not declaring a new variable `p`, you're *assigning* a value to an existing variable. See also:

```
int myVal;
myVal = 5;

```

Second, well, you're assigning to the variable `p`. Thus, it'll override whatever was in there before with the new value - in this case `new Element<K>()`. Technically this could be any value, but since you called `new`, it'll create a new variable and call the appropriate constructor. Don't worry about memory leaks - C# will keep track of orphaned references and clean them up for you.

Finally, since `p` is passed to your method as a [`ref`](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/ref), assigning to it will edit both the variable `p` in the local scope of the method AND the reference passed to your method from the calling scope, hence why assigning to `p` is useful as an output here.
You'll notice the class of the p variable is `Element<K>` from the method signature on line one. Ignoring for the moment that it's passed by ref, it's the similar to the following code.

```
Element<K> p = new Element<K>();

```

Element is a generic class of type K. K is the type of object that is being sorted. It's generic because you can choose the type of element that is being sorted. So if you were sorting cars, for example.

```
Element<Car> c = new Element<Car>();

```

The logic of what types are allowed is defined inside the definition of the generic `Element<K>` class.