c#检查string []中的索引是否在数组中彼此相邻 [英] c# check if index's in string[] are next to each other in array

查看:154
本文介绍了c#检查string []中的索引是否在数组中彼此相邻的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

c#:如何检查输入字符串[]的索引是否彼此相邻?





string [] a = {one,two,three,four,five,six,seven,eight};



string [] input = {three,one,four,two};



if(输入索引是彼此相邻的)

{

MessageBox.Show(OK);

}

解决方案

< blockquote>将索引转换为数组。

对数组进行排序。

如果数组中的值都是前一个值的单个增量,则字符串都是下一个彼此。



.NET中有一个Array.Sort方法,或<的简单 code> foreach 循环将检查结果。


c#: How do I check if index's of input string[] are next to each other ?


string[] a = {"one","two","three","four","five","six","seven","eight"};

string[] input = {"three", "one", "four", "two"};

if(input index's are next to each other)
{
MessageBox.Show("OK");
}

解决方案

Get the indexes into an array.
Sort the array.
If the values in the array are all a single increment from the previous value, the strings are all next to each other.

There is an Array.Sort method in .NET, and a simple for or foreach loop will check the results.


这篇关于c#检查string []中的索引是否在数组中彼此相邻的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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