using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
namespace XiaoTuNi.test.Study
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
...{
public class test_FindElement
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private static test_FindElement _test_FindElement;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public static test_FindElement GetTest_FindElement
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
get
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
if (_test_FindElement == null)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
_test_FindElement = new test_FindElement();
}
return _test_FindElement;
}
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="searchArray"></param>
/// <param name="searchValue"></param>
/// <returns></returns>
private int findElement<T>(T[] searchArray, T searchValue) where T : IComparable
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
int maxCount = searchArray.Length ;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (maxCount > 0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
for (int i = 0; i < maxCount; i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
if (searchArray[i].CompareTo(searchValue) == 0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
return i;
}//End if;
}//End for;
}//End if;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return -1;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
///
/// </summary>
/// <returns></returns>
public string CallGenericProcedure()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
string[] stringArray = ...{ "廖海兵", "白杰", "小样", "大样" };
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string stringSearch = "小样";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
int[] integerArray = ...{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 11, 21, 13, 14, 15, 16, 17 };
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int integerSearch = 11;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int mPosition = 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
StringBuilder sb = new StringBuilder();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
mPosition = findElement<string>(stringArray, stringSearch);//开始查找
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (mPosition < 0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
sb.AppendLine("找不到字符串" + stringSearch);
}
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
sb.AppendLine("在位置" + mPosition.ToString() + "处找到" + stringSearch);
}//End if;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
mPosition = findElement<int>(integerArray, integerSearch);//开始查找
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (mPosition < 0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
sb.AppendLine("找不到字符串" + integerSearch);
}
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
sb.AppendLine("在位置" + mPosition.ToString() + "处找到" + integerSearch);
}//End if;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return sb.ToString();
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
}
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)