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

This forum is meant for questions about the Visual FoxPro Language support in X#.

Post Reply
Anonymous

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

Post 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??
User avatar
Chris
Posts: 4593
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

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

Post 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.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
Post Reply