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();
}
}
}
查看全文
相关阅读:
谈谈关于MVP模式中V-P交互问题
Delphi MVC模 2
Delphi MVC模式 1
Java长整除问题
Java中Scanner类的简单用法
Java中throw和throws的区别
Java必须掌握的运算符
Java编程多重循环
Java实现三种简单的排序
使用Java向properties存数据
原文地址:https://www.cnblogs.com/xiaotuni/p/2365724.html
最新文章
清点人数
【哈希和哈希表】Beads
【哈希和哈希表】Antisymmetry
Shell脚本的fork炸弹
脚本_查找 Linux 系统中的僵尸进程
优化Nginx并发访问量
如何启用Nginx的status功能,查看服务器状态信息?
Nginx优化_自定义报错页面
脚本_删除某个目录下大小为 0 的文件
使用脚本自动创建逻辑卷
热门文章
Nginx的TCP/UDP调度器
Nginx的反向调度功能
脚本_使用awk提取linux主机参数
delphi消息结构
Delphi多线程及消息发送传递结构体参数 转
Delphi 指针及其它(转)
Variant类型
DelphiXE 显示GIF动画 转老帅
Delphi事件的广播 转
Delphi XE中类成员的访问权限******
Copyright © 2011-2022 走看看