开发者

Converting a C# code to F#

开发者 https://www.devze.com 2023-01-02 22:38 出处:网络
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];

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 |]

Is it correct? or should i use v1 like this 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 longs that contains a single element whose value is v1.Length. In F# it would be e.g.

[| 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)

?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号