English 中文(简体)
名单上的匹配和国名的区别
原标题:Put a match on list and get Distinct Country Names

在我前面的末尾,有两种选择选择选择国家,一种选择是[决定:单一选择Don List],另一种选择是[访问的国家:多位选择的DopDown List],所有数值都出现在“共享点清单”中,首先作为“乔斯”领域,另一种是“审查代码”价值(同上,p Value,#id#;# Value)。

现在,我有一个搜索页,用户可以从国家下降中选择标准: 为了填补退学问题,我选择了所有与外地居民不同的价值观,我需要从国家参观的价值观中获取这些价值观,并将它作为独特的价值观加以削减。

我不能认为从一个多选择的领域提取不同价值观的逻辑,然后将其与经常选择的外地价值进行比较,例如:

   Resident of             Countries Visited

a) Canada                  Chile,Argentina,Russia.
b) Peru                    Canada,Russia,Spain,Germany.

现在,在装上下倒数的同时,我如何从上述清单中获取不同的价值观。

问题回答

为此:

string countries1 = "Chile,Argentina,Russia";
string countries2 = "Canada,Russia,Spain,Germany";
var countryLists = new List<string>() { countries1, countries2 };
var distinctCountries = countryLists.Select( s => s.Split( , ))
    .SelectMany(list => list, (list, country) => country)
    .Distinct();

解释

  • Create a collection of comma separated strings
  • Use string.Split to project this into a collection of collections of strings
  • Use SelectMany to flatten this into a single list
  • Use Disting to remove duplicates

如果你也希望把居民名单与这份名单合并,我就不谈这个问题。 如果是的话,请在结尾处填写Union( ResidentCountries)而不是Dis本()。

简化@Mike Goodwin 回答:

string countries1 = "Chile,Argentina,Russia";
string countries2 = "Canada,Russia,Spain,Germany";
var countryLists = new List<string>() { countries1, countries2 };
var distinctCountries = string.Join(",", countryLists).Split( , ).Distinct();

但这并不能回答这一问题。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签