why the "GetComponent()" add "as" sometimes?

`Test test1;`

test1=gameObject.GetComponent("Test1") as Test1;

the return of "GetComponent()" is type of Component Originally. why add "as" also? I think use the following also achieve the same effect. why???

`Test test1=new Test();`

In c# you can only assign to a variable with the same type or a base type of the object you have (unless there is an implicit cast operator written to convert them)

E.g.

Component c = GetComponent("Test1");

will work fine, as whatever comes from the function is a component itself

If you try to assign to a variable with a more specialized child class, it'll fail, because any type of component could come from the function, not just the type you want

What you need to do in those cases is cast the value to the type you want - and that's what "as" is doing.