简体   繁体   中英

Converting a C# code to F#

I am just a beginner in programing i wish covert some code from C# to F#,

I have encotered this code:

float[] v1=new float[10];

...

//Enqueue the Execute command. 
Queue.Execute(kernelVecSum, null, **new long[] { v1.Length }**, null, null);

I have previously ask how to convert the v1 object, I think i know how, But how do i use the function call especially the new long[] { v1.Length } part of the function argument, what does new long[] { v1.Length } mean??

I have created v1 like this let v1 = [| for i in 1.0 .. 10.0 -> 2.0 * i |] let v1 = [| for i in 1.0 .. 10.0 -> 2.0 * i |]

Is it correct? or should i use v1 like this let v1 = ref [| for i in 1.0 .. 10.0 -> 2.0 * i |] let v1 = ref [| for i in 1.0 .. 10.0 -> 2.0 * i |] ?

This is really more of a C# question... you might tag it as such.

In C#

new long[] { v1.Length }

creates a new array of long s that contains a single element whose value is v1.Length . In F# it would be eg

[| int64 v1.Length |]

(In any case, no, you don't want the ref in the F# code. And you still have not corrected the data type as suggested here .)

Queue.Execute(kernelVecSum, null, [| int64 (v1.Length) |], null, null)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM