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();
}
}
}
查看全文
相关阅读:
INFORMIX体系效能改善第一步
Ubuntu判袂率不正常的一种复杂治理措施
ubuntu8.04分区分配方案
计算机启动更快的十五招
理顺 JavaScript (13) 对象及 json
获取指定地址的 JPG 图片 回复 "bangrj" 的问题
理顺 JavaScript (14) constructor 与 instanceof
理顺 JavaScript (9) Date 类
用 API 提取、写入指定网站的 Cookie 回复 "bangrj" 的问题
理顺 JavaScript (10) Math 类
原文地址:https://www.cnblogs.com/xiaotuni/p/2365724.html
最新文章
一种可做特殊用途的字符串匹配算法
Android开发环境搭建全程演示(jdk+eclip+android sdk)
标记一个:HookQQ QQFun CWUB
ArcSDE 发布 WMS 服务出错
C语言版农历算法
ubuntu 8.04 中文输入法 中文撑持
suse 10.3的布置源
Ubuntu 8.10能够的上岸界面
ubuntu8.04首验觉得
让debian直接启动到下令行形式
热门文章
措置suse安设黑屏
ubuntu从7.10进级到8.04后CHMSEE不克不及启动的处置
双细碎摆设Linux之后找不到Windows分区
Debian下彻底删除Gnome和KDE的要领
学好Windows是Linux的根本内幕
DEBIAN/LINUX零碎下的声卡铺排
Novell Best of Brainshare Tour 2008
一个MySQL5的无法访谒的效果
Ganglia install and configure
linux控制台字体的设置
Copyright © 2011-2022 走看看