F# 获取无效驱动器号的列表
我遵循了,但无法将其应用于我的问题,因为我看到的两个解决方案似乎都没有编译。List.Contains不存在(缺少引用?),ListA-ListB也不编译。您的第一个错误是混合了F# 获取无效驱动器号的列表,f#,sequences,F#,Sequences,我遵循了,但无法将其应用于我的问题,因为我看到的两个解决方案似乎都没有编译。List.Contains不存在(缺少引用?),ListA-ListB也不编译。您的第一个错误是混合了char和string,最好从char开始: let private GetDrives = seq{ let all=System.IO.DriveInfo.GetDrives() for d in all do //if(d.IsReady && d.DriveType=System.IO.D
char
和string
,最好从char
开始:
let private GetDrives = seq{
let all=System.IO.DriveInfo.GetDrives()
for d in all do
//if(d.IsReady && d.DriveType=System.IO.DriveType.Fixed) then
yield d
}
let valid={'A'..'Z'}
let rec SearchRegistryForInvalidDrive (start:RegistryKey) = seq{
let validDrives=GetDrives |> Seq.map (fun x -> x.Name.Substring(0,1))
let invalidDrives= Seq.toList validDrives |> List.filter(fun x-> not (List.exists2 x b)) //(List.exists is the wrong method I think, but it doesn't compile
open System.IO
let driveLetters = set [ for d in DriveInfo.GetDrives() -> d.Name.[0] ]
let unused = set ['A'..'Z'] - driveLetters
现在,无效驱动器号是指all
中但不在validAddress
中的驱动器号:
let all = {'A'..'Z'}
let validDrives = GetDrives |> Seq.map (fun x -> x.Name.[0])
您的第一个错误是混合了
char
和string
,最好从char
开始:
open System.IO
let driveLetters = set [ for d in DriveInfo.GetDrives() -> d.Name.[0] ]
let unused = set ['A'..'Z'] - driveLetters
现在,无效驱动器号是指all
中但不在validAddress
中的驱动器号:
let all = {'A'..'Z'}
let validDrives = GetDrives |> Seq.map (fun x -> x.Name.[0])
所以你可以减去集合,但不能减去序列?在c#中最接近集合的是什么?@Maslow:
System.Collections.Generic.HashSet
,LINQ有许多类似集合的操作;未使用。除(大写字母)外代码>所以你可以减去集合,但不能减去序列?在c#中最接近集合的是什么?@Maslow:System.Collections.Generic.HashSet
,LINQ有许多类似集合的操作;未使用。除(大写字母)外代码>