简体   繁体   English

c#LINQ加入逗号分隔的字符串

[英]c# LINQ joining to comma separated string

I have a string of comma separated values called driverids. 我有一串逗号分隔值,称为driverids。

  1. Should I use the comma separated list or the array that this comma separated list comes from to use this in a join. 我应该使用逗号分隔列表或此逗号分隔列表来自的数组来在连接中使用它。

  2. How would I use a join in linq to these driverids? 我如何在linq中使用这些驱动程序的连接?


_currentDriverData.AddRange(elementsCurrent.Join(driverids)

// gets distinct driver ids from the driver duty status change logs;
string driverids = string.Join(",", _logsDutyStatusChange
                         .Select(item => item.did)
                         .Distinct()
                         .ToArray());

//gets all current driver information
//_currentDriverData.AddRange(elementsCurrent.Where(drivers)

_currentDriverData.AddRange(elementsCurrent.Join(driverids).Select.........

你会做这样的事情(假设_currentDriverData是一个id列表):

_currentDriverData.AddRange(commaSeparatedString.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyElements).ToList());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM