I came across a bit of code today that I'm trying to get my head around and trying to understand the advantages of using "where : class" in the method definition.

Code obviously simplified.

```
    private class Test
    {
        public int A { get; set; }
        public int B { get; set; }
    }

    private AB Invoke<AB>() where AB : class
    {
        return new Test() as AB;
    }

    private object RunMethod()
    {
        return new Test();
    }

```

Each method is called in the following ways.

```
// Method1
Test ResultTest = Invoke<Test>();

// Method2
Test ResultTest = RunMethod() as Test;

```

Are there any other advantages apart from not having to Cast or use "as".
Also what is this called?