There is a methods which is accepting a parameter of type List<long?>
, I need to assign it to someTestModel ids, which are of type ISet<long>
.
public void testM1(List<long?> testIds)
{
var request = new someTestModel { ids= testIds };
}
There's two things we'd need here:
ISet<T>
- presumably HashSet<T>
will suffice long?
to long
- presumably by just ignoring any that are null
So, something like:
var hash = new HashSet<long>();
foreach(var id in testIds) {
if(id.HasValue) hash.Add(id.Value);
}
var request = new someTestModel{ ids = hash};
?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.