xsharp.eu • Why is "AS Type" required?? Can't compiler figure that out??
Page 1 of 1

Why is "AS Type" required?? Can't compiler figure that out??

Posted: Fri Oct 18, 2019 9:26 pm
by Anonymous
If I have this line of code

Code: Select all

Local oObject = myNS.MyFirstClass{} As MyFirstClass
What do I have to put "As MyFirstClass" at the end of the line? Because to the right of the = sign it tells it right there the name of the class, and perhaps even the namespace. It just seems redundant that we have to specify it. What else could it be besides that same Type?

Is this perhaps to allow support for Interfaces or some other kind of inheritance or sublassing thing that I am missing.

Since the VAR keyword could be used and it can figure it out, what can't it figure it out if we leave of the AS clause??

Why is "AS Type" required?? Can't compiler figure that out??

Posted: Fri Oct 18, 2019 10:06 pm
by Chris
Hi Matt,

You may want to type it as a parent class of the class you instantiate. Or you may want to type it AS OBJECT, so you can assign a different object to this local later. Or as an interface. Or as nothing (so it becomes a usual type).

If you do not want to specify the type, you can use VAR.