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();
}
}
}
查看全文
相关阅读:
奖学金 题解
大数加法
删除倒数第 N 个节点
css中行内元素默认间隙解决方案
vuecli3项目中优化lodash/moment使用
谷歌浏览器input输入框自动填充数据
vuecli3首页白屏优化
highcharts开发交易所的行情走势图
react-native使用flatlist上拉加载下拉刷新
放大预览图片不失真
原文地址:https://www.cnblogs.com/xiaotuni/p/2365724.html
最新文章
xml
2016年8月17日 内省(1)18_黑马程序员_使用beanUtils操纵javabean
2016年8月8日
eclipse快捷键:
根据指定进程得到端口
程序猿必读书单
基于Arcgis Engine的坐标转换
sde数据操作
arcgis project gp工具
使用ArcGIS实现WGS84经纬度坐标到北京54高斯投影坐标的转换
热门文章
搭建windows mobile 开发环境
oracle汉字乱码
AE调用gp服务
ArcGIS Server 10.0安装
生成word并保存
判断链表的回文结构
BST 树和满二叉树的性质
炮台攻击
小易的升级之路 #约数
路灯 #暴力题
Copyright © 2011-2022 走看看