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();
}
}
}
查看全文
相关阅读:
一个图层隶属下一个图层
windows安装Apache,注册服务出现“(OS 5)拒绝访问。 : AH00369: Failed to open the WinNT service manager..."错误
windows下apache如何完整卸载?
重设mysql数据库root用户密码
mysql设置root密码
mysql服务无法启动
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables opt
亿丰之星 · 声动亚洲
Euler's Sum of Powers Conjecture
MATLAB Hacks from Richard Socher
原文地址:https://www.cnblogs.com/xiaotuni/p/2365724.html
最新文章
布局
(づ ̄3 ̄)づ╭❤~
Hexo 版本
JSONP
小程序wxss编译错误
Chrome focus样式
ANT DESIGN
HTML字符实体
筛选
关闭某个端口对应的应用
热门文章
矩阵求连续递减序列个数,动态规划初级,递归,poj1088
最大子矩阵,最大连续子数组进阶,动态规划初级,poj1050
最大连续子数组,动态规划基础
poj1018,动态规划初级,状态转移方程
构建队列,数组版本
快速排序,排序基础
堆排序,优先队列,排序基础
最大子数组问题,分治策略基础,百度面试题
硬币找零问题,动态规划基础,百度面试题
poj1083,基本互斥问题
Copyright © 2011-2022 走看看