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: 
`p` if by `ref` in the method so whatever you do it is affected outside of it; meaning when you assign it with `new` the caller of the method's parameter of `p` is also reassigned. 

You're stating it's an `Element<K>` type in the parameter so `p` must conform to that type.

In the method, the line in question, you reassign `p` to a `new Element<K>` via 

```
p = new Element<K>();//what happens here?

```

This is the same as `p = new Element()` in terms of how you're use to seeing it but since the `Element` type requires an generic type reference (which could be `K` or anything else) you need to also reassign it with the same type `K` passed to the method. Because we don't know for sure what type `K` is when called.

The reason you're not using `var p =...` or `Element<K> p =..` is because `p` is already declared as that type in the parameter. It's a `ref` parameter so you can just reassign it as mentioned.

The caller of the method may be like this as example only:

```
Element<string> p = null;
string k = "someKey";
_InsertIntoBinarySearchTree(ref p, k); //Here p goes into the method as ref; the method performs the null check and sets p as new Element<string>()

```

Hope this helps...
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.