小编wan*_*gzq的帖子

为什么这个代码不能在VS2010中用.NET 4.0编译?

不知何故,以下代码无法在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)

.net c# linq visual-studio-2010 visual-studio-2012

9
推荐指数
1
解决办法
827
查看次数

F#中的多个构造函数和类继承

我很难将以下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)

f#

7
推荐指数
1
解决办法
1650
查看次数

vim location-list:如果在最后位置,如何去第一个位置

我已映射gn:lnext<cr>; 如何按住它来循环通过位置列表,即如果在最后位置则转到第一个?

谢谢

vim

5
推荐指数
2
解决办法
1032
查看次数

来自F#的EnumWindows

我试图从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)

f# dllimport

2
推荐指数
1
解决办法
215
查看次数

标签 统计

f# ×2

.net ×1

c# ×1

dllimport ×1

linq ×1

vim ×1

visual-studio-2010 ×1

visual-studio-2012 ×1