不知何故,以下代码无法在VS2010中编译,而是在VS2012中编译而不进行更改.VS2010中有问题的一行是
names.Select(foo.GetName)
Run Code Online (Sandbox Code Playgroud)
错误CS1928:'string []'不包含'Select'的定义和最佳扩展方法重载'System.Linq.Enumerable.Select <TSource,TResult>(System.Collections.Generic.IEnumerable <TSource>,System. Func <TSource,TResult>)'有一些无效的参数.
using System;
using System.Linq;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
var foo = new Foo();
var names = new[] {"Hello"};
Console.WriteLine(string.Join(", ", names.Select(foo.GetName)));
}
}
public class Foo
{
}
static class Extensions
{
public static string GetName(this Foo foo, string name)
{
return name;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我很难将以下C#代码转换为F#:
class Foo
{
public Foo() { }
public Foo(string name) { }
}
class Bar : Foo
{
public Bar() : base() { }
public Bar(string name) : base(name) { }
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我第一次尝试跟随,但报告错误
"Bar"类型的构造函数必须直接或间接调用其隐式对象构造函数.使用对隐式对象构造函数的调用而不是对记录表达式的调用.
type Foo() =
new(name:string) = Foo()
type Bar() =
inherit Foo()
new(name:string) = { inherit Foo(name) }
member val Name:string = null with get, set
Run Code Online (Sandbox Code Playgroud)
然后我试着跟随,但它现在报告auto属性的错误
'member val'定义仅允许在具有主构造函数的类型中使用.考虑为您的类型定义添加参数"
type Foo() =
new(name:string) = Foo()
type Bar =
inherit …Run Code Online (Sandbox Code Playgroud) 我已映射gn到:lnext<cr>; 如何按住它来循环通过位置列表,即如果在最后位置则转到第一个?
谢谢
我试图从F#调用EnumWindows并得到以下异常:
System.Runtime.InteropServices.MarshalDirectiveException: Cannot marshal 'parameter #1': Generic types cannot be marshaled.
Run Code Online (Sandbox Code Playgroud)
我使用的代码:
module Win32 =
open System
open System.Runtime.InteropServices
type EnumWindowsProc = delegate of (IntPtr * IntPtr) -> bool
[<DllImport("user32.dll")>]
extern bool EnumWindows(EnumWindowsProc callback, IntPtr lParam)
let EnumTopWindows() =
let callback = new EnumWindowsProc(fun (hwnd, lparam) -> true)
EnumWindows(callback, IntPtr.Zero)
module Test =
printfn "%A" (Win32.EnumTopWindows())
Run Code Online (Sandbox Code Playgroud)