F#Array实例化5个项目但不包含6个项目

Roo*_*noy 6 arrays f#

我是F#的新手,所以我可能错过了一些微不足道的东西,但是这里有.

这工作 -

let monthsWith31Days = [| MonthType.January; 
                          MonthType.March;
                          MonthType.May;
                          MonthType.July;
                          MonthType.December |]
Run Code Online (Sandbox Code Playgroud)

但事实并非如此

let monthsWith31Days = [| MonthType.January; 
                          MonthType.March;
                          MonthType.May;
                          MonthType.July;
                          MonthType.August;
                          MonthType.December |]
Run Code Online (Sandbox Code Playgroud)

我所注意到的不是内容本身,而是重要的项目数量(即使我更改了实际使用的项目).当项目数超过5时,问题就开始了.

这是我运行NUnit测试时得到的错误 -

System.ArgumentException:值不在预期范围内.

我缺少什么想法?

编辑:

整个类型定义(两种类型相关,因此在这里显示) -

type public Month(monthType:MonthType, year:Year) = 
        member public this.Year 
            with get () = year
        member public this.MonthType 
            with get () = monthType

        member public this.GetDaysCount () = 
            let monthsWith31Days = [| MonthType.January; 
                                      MonthType.March;
                                      MonthType.May;
                                      MonthType.July;
                                      MonthType.August;
                                      MonthType.December |]

            let has31 = monthsWith31Days |> Array.filter(fun n -> (int)n = (int)this.monthType) |> Array.length

            if (has31 > 0)
            then 31
//            else if (this.MonthType = MonthType.February)
//            then (if this.Year.Leap then 29 
//                  else 28)
            else 30


    and public Year(ad:int) = 
        member public this.AD
            with get() = ad

        member public this.Months = Enum.GetValues(typeof<MonthType>).Cast().ToArray()
                                    |> Array.map(fun n -> new Month (n, this))

        member public this.GetMonth (index:int) = 
            (this.Months |> Array.filter(fun p-> (int)p.MonthType = index)).First()

        member public this.GetMonth (monthName:string) = 
            let requiredMonthType = Enum.Parse(typeof<MonthType>, monthName) |> unbox<MonthType>
            (this.Months |> Array.filter(fun p-> p.MonthType = requiredMonthType)).First()

        member public this.Leap = 
            if this.AD % 400 = 0 then true
            else if this.AD % 100 = 0 then false
            else if this.AD % 4 = 0 then true
            else false

        member this.DaysCount = if this.Leap then 366 else 365
Run Code Online (Sandbox Code Playgroud)

Bri*_*ian 6

其实,我依稀记得关于创建充分一些目标CLR平台,在这里,如果你有超过5个,然后产生什么的一些不好的代码枚举数组常量一些bug.也许你打的那个?你的目标是x64和CLR2吗?您可以通过避免数组文字来解决错误,并使用例如列表然后调用List.ToArray.