Public Sub Delay (ByRef HowLong As Double) On Error Resume Next Dim throughTime As DateTime Dim Dnow As DateTime = DateTime.Now 'throughTime = DateAdd (DateInterval.Second, HowLong, Now) throughTime = Dnow.AddSeconds (HowLong) Do While throughTime> DateTime.now Application.doevents () loop end sub turn to C # As follows, there is a problem: public void delay (Ref double howlong)
{DateTime DNOW = DateTime.Now; Throughtime = DNOW.Addseconds (Howlong); While (THROUGHTIME> DATETIME.NOW) {Application.doevents ();}}
Error 1 and "Delay (Ref Double Howlong)" Matched Overload Method Has Some Invalid Parameters Error 2 Parameters "1" Unable to convert from "INT" to "Ref Double"
Ask everyone. I don't understand it for C #, how do I modify? Public void delay (double howlong) is just fine, don't need to use Ref Hu Guohong's view:
Error 1 and "Delay (Ref Double Howlong)" Matched Overload Method Has Some Invalid Parameters Error 2 Parameters "1" Unable to convert from "INT" to "Ref Double"
The above two errors are actually a mistake because your call writes:
DELAY (20)
The compiler explains 20 as int types, naturally goes to find
DELAY (int howlong) function, and you only define Delay (Ref Double Howlong) functions
The above error occurs when INT type implicitly converted to Ref Double. The reason why VB has nothing wrong because the compiler option default setting is: option strict == OFF
The correct method is called in the following manner:
DELAY 20); DELAY ((DOUBLE) 20);
I tested it and compiled. My analysis is that the compiler interprets the parameters 20 as the right value (REF), and the parameters defined by the Ref definition must be left, LValue. So an error. Another reason is that the Double type cannot be implicitly converted to Ref Double.
The following methods can be used:
Method 1, as said 8620 (TUENHAI), change public void delay (ref double way ", defined as public void delay (double howlong)
Method 2, do not change the definition, change the mode of call