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();
}
}
}
查看全文
相关阅读:
CSS3 页面跳转的动画效果
JS/React 判断对象是否为空对象
React 根据官方总结的规范
ckeditor字数限制
swfobject.js IE兼容问题
Jcrop 做图片剪裁 在IE中无法显示问题解决办法
WebApp 中用 hashchange 做路由解析
全国省市区Json文件 ,做省市区联动很轻松
解决用友U8删除用户时提示“用户已启用”不能删除的问题
CFUpdate高速模式下出现Error #2038提示的解决方案
原文地址:https://www.cnblogs.com/xiaotuni/p/2365724.html
最新文章
布局共享(列如所有activity拥有相同的布局部分,比如actionbar,在BaseActivity中写入布局)
android:showAsAction="never"是做什么用的?
Eclipse项目导入Android Stuio 配置出现 Timeout waiting to lock buildscript class cache for build file 'H:studioprojectGeneric_SNuild.gradle'
Android ActionBar 返回为NULL
JAVA回调函数ANDROID中典型的回调地方
JAVA三大特性之多态
《转》JAVA动态代理(JDK和CGLIB)
Android Frament的切换(解决replace的低效)
List 常用方法解析
窗体拖动
热门文章
ComboBoxEdit 添加键值
C#监测方法执行效率
Task.Factory.StartNew多线程中将数值实时传递到UI显示
判断数组是否有重复值
数组去重
vuex的状态管理模式
修改ElementUI源码
WebStorm2018.2 破解 激活
React Native ——实现一个简单的抓取github上的项目数据列表
React Native 重新建项目遇到的一些问题
Copyright © 2011-2022 走看看