zoukankan
html css js c++ java
利用泛型搜索出不同数据类型所在位置.
using
System;
using
System.Collections;
using
System.Collections.Generic;
using
System.Text;
namespace
XiaoTuNi.test.Study
...
{
public
class
test_FindElement
...
{
private
static
test_FindElement _test_FindElement;
public
static
test_FindElement GetTest_FindElement
...
{
get
...
{
if
(_test_FindElement
==
null
)
...
{
_test_FindElement
=
new
test_FindElement();
}
return
_test_FindElement;
}
}
/**/
///
<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
...
{
int
maxCount
=
searchArray.Length ;
if
(maxCount
>
0
)
...
{
for
(
int
i
=
0
; i
<
maxCount; i
++
)
...
{
if
(searchArray[i].CompareTo(searchValue)
==
0
)
...
{
return
i;
}
//
End if;
}
//
End for;
}
//
End if;
return
-
1
;
}
/**/
///
<summary>
///
///
</summary>
///
<returns></returns>
public
string
CallGenericProcedure()
...
{
string
[] stringArray
=
...
{
"
廖海兵
"
,
"
白杰
"
,
"
小样
"
,
"
大样
"
}
;
string
stringSearch
=
"
小样
"
;
int
[] integerArray
=
...
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
0
,
11
,
21
,
13
,
14
,
15
,
16
,
17
}
;
int
integerSearch
=
11
;
int
mPosition
=
0
;
StringBuilder sb
=
new
StringBuilder();
mPosition
=
findElement
<
string
>
(stringArray, stringSearch);
//
开始查找
if
(mPosition
<
0
)
...
{
sb.AppendLine(
"
找不到字符串
"
+
stringSearch);
}
else
...
{
sb.AppendLine(
"
在位置
"
+
mPosition.ToString()
+
"
处找到
"
+
stringSearch);
}
//
End if;
mPosition
=
findElement
<
int
>
(integerArray, integerSearch);
//
开始查找
if
(mPosition
<
0
)
...
{
sb.AppendLine(
"
找不到字符串
"
+
integerSearch);
}
else
...
{
sb.AppendLine(
"
在位置
"
+
mPosition.ToString()
+
"
处找到
"
+
integerSearch);
}
//
End if;
return
sb.ToString();
}
}
}
查看全文
相关阅读:
Pro*C,oci,occi的作用以及区别联系?
图片缩放 剪切
去除DataGridView选中行背景色的方法
重写DataGridView的sort方法 自定义排序
很好用的js日历 kimsoftjscalendar 感谢KimSoft
计时器例子
gcc与g++有什么区别?
VB.NET全角半角check
Java 集合框架(Collection)和数组的排序
Click Models for Web Search(1) Basic Click Models
原文地址:https://www.cnblogs.com/xiaotuni/p/2365724.html
最新文章
栈实现综合计算器(中缀表达式)
逆波兰计算器实现
逆波兰表达式完整实现
C#实现判断一远程文件(图片等)是否存在
PostgreSQLBytea字段读取出错
Construct the intermediate positions, the ribs along two rails
Rebuild 3rd Libraries
早期人肉实现 - 简单排序算法代码
导入包
我的博客园开始启用啦
热门文章
单管控制方式(慢续流方式) 和双管控制方式(快续流方式) 的适用场合
Keil 打开后,没有在任务栏出现,但是任务管理器中有相应的任务
RT Thread IPC总结
笔试题面试题汇总
从CortexM3的MSP 和PSP谈Linux能否在中断中使用Sleep
Linux点滴
ARM(CortexM3)的中断向量
uC/OS 的任务调度解析
南京趋势科技面试归来
用正则表达式Trim js方法
Copyright © 2011-2022 走看看