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();
}
}
}
查看全文
相关阅读:
最小移动次数使数组元素相等
计算几何
北校门外的回忆
洗衣服
HDU1046:Gridland
注册机的实现如(istarMenu CORE Keygen)
是你吗?
(译)KVO的内部实现
通过UIColor转换为UIImage
Palindrome Number 解题报告
原文地址:https://www.cnblogs.com/xiaotuni/p/2365724.html
最新文章
SQL查询
Jmeter,数据库压力测试
jmeter之 jp@gc
Web安全测试-WebScarab
datafactory-如何快速生成大批量数据
FFmpeg去掉B帧
图像超分
screen显示窗口查看历史输出
iTerm2 快捷键大全
FFmpeg码率控制及内置编码参数介绍
热门文章
视频编码中CBR和VBR的区别,CRF和CQP的区别
码率是什么?比特率是干嘛的?帧速率是啥?分辨率又是什么?
HEVC参数profile(档次)、level(水平)、tire(等级)整理
BD-RATE计算原理
SSIM & MS-SSIM评价函数
图论基础
曼哈顿距离与切比雪夫距离及其相互转化
#509. 「LibreOJ NOI Round #1」动态几何问题
[十二省联考2019]皮配
Gym-100451B:Double Towers of Hanoi
Copyright © 2011-2022 走看看