将第一个列表元素与列表的第二个元素进行比较 [英] compare the first list element to second element of list

查看:130
本文介绍了将第一个列表元素与列表的第二个元素进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将第一个列表元素与列表的第二个元素进行比较并返回第二个元素,第三个到第四个,然后以c#语言返回第四个元素

,例如

newList [i] .Endswith(newList [i + 1])

返回newList [i + 1]



但它无法正常工作。是否有解决此类问题的最佳解决方案

I want to compare the first list element to second element of list and return 2nd element, third to fourth and and return fourth in c# language
such as
newList[i].Endswith(newList[i+1])
return newList[i+1]

but it is not working correctly. is there any the best solution to solve such problem

推荐答案

尝试:

Try:
for (int i = 0; i < newList.Count - 1; i++)
   {
   if (newList[i].EndsWith(newList[i + 1]))
      return newList[i + 1];
   }







这只返回最后匹配条件。

如果我们有[0]读,[1] ad和[2]盐,[3] alt它只返回'alt'它还返回'ad'和'alt'




如果你想做什么,那么你必须向我们解释一下!

请记住,我们无法看到您的屏幕,访问您的硬盘或阅读您的想法。:laugh:



试试这个:




"This return only last matching condition.
if we have [0]read ,[1]ad and [2]salt, [3]alt it return only last 'alt' it also return 'ad' and 'alt'"


If that's what you want to do, then you have to explain it to us!
Remember that we can't see your screen, access your HDD, or read your mind.:laugh:

Try this:

List<string>>matches = new List<string>();
for (int i = 0; i < newList.Count - 1; i++)
   {
   if (newList[i].EndsWith(newList[i + 1]))
      matches.Add(newList[i + 1]);
   }

匹配列表包含所有ad和alt值。

The matches list contains all the "ad" and "alt" values.


这篇关于将第一个列表元素与列表的第二个元素进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆