Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 从自定义类型F的列表中筛选不同的值#_.net_List_F#_Sequence - Fatal编程技术网

.net 从自定义类型F的列表中筛选不同的值#

.net 从自定义类型F的列表中筛选不同的值#,.net,list,f#,sequence,.net,List,F#,Sequence,给定一个整数列表,我们可以执行以下操作以获得不同值的列表 let myList = [ 1; 2; 2; 3; 4; 3 ] let distinctList = myList |> Seq.distinct |> List.ofSeq 但是,在我的例子中,我有一个自定义类型的列表,定义如下: type Listing(fromDate:NSDate, toDate:NSDate, pricePerNight:int, landlordId:String, landlordName

给定一个整数列表,我们可以执行以下操作以获得不同值的列表

let myList = [ 1; 2; 2; 3; 4; 3 ]
let distinctList = myList |> Seq.distinct |> List.ofSeq
但是,在我的例子中,我有一个自定义类型的列表,定义如下:

type Listing(fromDate:NSDate, toDate:NSDate, pricePerNight:int, landlordId:String, landlordName:String, listingId:String, pic1url:NSUrl, pic2url:NSUrl, pic3url:NSUrl, pic4url:NSUrl, pic5url:NSUrl, postcode:String, latitude:Double, longitude:Double, location:String, partnername:String,partnerid:String) = 
 member this.fromDate : NSDate = fromDate
 member this.toDate : NSDate = toDate
 member this.pricePerNight : int = pricePerNight
 member this.landlordId : String = landlordId
 member this.landlordName : String = landlordName
 member this.listingId : String = listingId
 member this.pic1url : NSUrl = pic1url
 member this.pic2url : NSUrl = pic2url
 member this.pic3url : NSUrl = pic3url
 member this.pic4url : NSUrl = pic4url
 member this.pic5url : NSUrl = pic5url
 member this.postcode : String = postcode
 member this.latitude : Double = latitude
 member this.longitude : Double = longitude
 member this.location : String = location
 member this.partnername : String = partnername 
 member this.partnerid : String = partnerid 
let mutable listings : List<Listing> = List.Empty
接下来,我有一个定义如下的列表:

type Listing(fromDate:NSDate, toDate:NSDate, pricePerNight:int, landlordId:String, landlordName:String, listingId:String, pic1url:NSUrl, pic2url:NSUrl, pic3url:NSUrl, pic4url:NSUrl, pic5url:NSUrl, postcode:String, latitude:Double, longitude:Double, location:String, partnername:String,partnerid:String) = 
 member this.fromDate : NSDate = fromDate
 member this.toDate : NSDate = toDate
 member this.pricePerNight : int = pricePerNight
 member this.landlordId : String = landlordId
 member this.landlordName : String = landlordName
 member this.listingId : String = listingId
 member this.pic1url : NSUrl = pic1url
 member this.pic2url : NSUrl = pic2url
 member this.pic3url : NSUrl = pic3url
 member this.pic4url : NSUrl = pic4url
 member this.pic5url : NSUrl = pic5url
 member this.postcode : String = postcode
 member this.latitude : Double = latitude
 member this.longitude : Double = longitude
 member this.location : String = location
 member this.partnername : String = partnername 
 member this.partnerid : String = partnerid 
let mutable listings : List<Listing> = List.Empty
让可变列表:List=List.Empty
现在,我想筛选此列表以仅获取唯一值(如果某个值具有唯一的
listingId
,则该值是唯一的)。我可以用简单的方法将所有的
listingId
添加到字符串列表中,对字符串列表执行distinct操作,然后用distinct列表中的id提取列表,但我认为必须有更好的方法

可以与lambda函数一起使用,以获得唯一性所需的值:

listings |> Seq.distinctBy (fun l -> l.listingId)