Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP - .NET blog
Message
From
06/05/2009 20:47:43
 
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Miscellaneous
Thread ID:
01397536
Message ID:
01398266
Views:
136
>>As you know, that's not really what I had in mind :o) but yes, that does work.
>
>No I don't know what you mean. How is this different that what you can do in VFP:
>
>
>Test test = new Test('Hello',1,DateTime.Now);
>
>
>Same thing - you get a list of untyped vars in the constructor.
>
>+++ Rick ---

Am I missing something? If Test was defined with 3 arguments, all three are required. If the constructor is only set up for 3, you couldn't:

Test test = new Test('Hello',1);

I'd have to code a constructor for 0, 1, 2, and 3 arguments passed if I wanted any of them to be optional. I couldn't pass 2 and have the constructor run with only 2 passed and create a default value for the 3rd argument not passed (like vfp does) - it won't even compile. That's what I meant. You have to code for every possibility. You have to overload the constructor:
	public class Test
	{
		public Test()
		{
			// This is the no parameter constructor method.
		}

		public Test(string Mesg)
		{
			// This is the constructor with one parameter.

		}

		public Test(string Mesg, int Age)
		{
			// This is the constructor with two parameters.
		}

		// rest of the class members 
	}
in order to pass 0, 1, or 2 arguments. By optional, I meant: If I want to pass the 3rd argument, I have to create another constructor that handles 3 arguments. I can't put it all in one like in VFP:
llReturnVal = Test('Hello',1,DateTime.Now)

FUNCTION Test
LPARAMETERS qcMesg, qiAge, qdDateTime, qlFourthParam

*If qlFourthParam is not passed, it is .F.
*Any params not passed are .F.

*function code here

RETURN llReturnValue
That's what I meant by 'optional' parameters in one class like you can do in VFP.

(Sorry for all the typos :o)
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform