将指针C#类型转换为F#吗? [英] Converting a pointer C# type to F#?
问题描述
我只是编程的初学者,我希望隐蔽一些从C#到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]
我需要使用此指针传递给函数:
I need to use this pointer to pass to the function:
ComputeBuffer<float> bufV1 =
new ComputeBuffer<float>(Context, ComputeMemoryFlags.ReadWrite |
ComputeMemoryFlags.UseHostPointer, v1);
如果我像这样在F#中创建数组:
If i creat an array in F# like this:
let v1 = [| 1.0..10.0 |]
现在调用这样的功能:
let bufV1 = new ComputeBuffer<float>(Context,
ComputeMemoryFlags.ReadWrite |||
ComputeMemoryFlags.UseHostPointer, v1)
这是一个错误吗?如何传递指针?
Is it an error?? How do i pass a pointer??
推荐答案
(在.NET中,我们称这些对象为对象的引用; v1
是对数组对象.指针有所不同.)
(In .NET, we call these things references to objects; v1
is a reference to an array object. Pointers are something different.)
请注意,F#称为 float
是C#称为 double
的内容.您可能需要
Note that what F# refers to as float
is what C# calls a double
. You might need
let v1 = [| 1.0f .. 10.0f |]
其中后缀 f
使值成为F# float32
s(例如C# float
s).
where the f
suffix makes the values be F# float32
s (e.g. C# float
s).
这篇关于将指针C#类型转换为F#吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!