zoukankan
html css js c++ java
数组下标是字符串的实现
using System;
namespace Oceansoft.LOGERP.MessageClient.MessageHeadAffirm
{
///
<
summary
>
///
报文头的形成
///
作者:贾海天
///
</
summary
>
public
class MessageHead
{
//
相关数组中存储项目的数组
protected object
[]
_items;
//
数组中的项目数
protected
int
_
count
=
0
;
public
int
Length
{
get
{
return
_
count
;
}
}
public
object this
[
string key
]
{
get
{
return
KeyToObject(
key
);
}
set
{
AddToArray(
key
,value);
}
}
protected bool KeyExists(string
key
)
{
for
(
int
n
=
0
;n
<
_
count
;n
++
)
{
KeyItemPair pair
=
(KeyItemPair)_items
[
n
]
;
if
(pair.
key
==
key
)
{
return
true;
}
}
return
false;
}
protected void AddToArray(string
key
,object item)
{
if
(!KeyExists(
key
))
{
_items
[
_count
]
=
new KeyItemPair(
key
,item);
_
count
++
;
}
}
protected object KeyToObject(string
key
)
{
for
(
int
n
=
0
;n
<
_
count
;
++
n)
{
KeyItemPair pair
=
(KeyItemPair)_items
[
n
]
;
if
(pair.
key
==
key
)
{
return
pair.item;
}
}
return
null
;
}
public
MessageHead(
int
MessageHead_Length)
{
//
//
TODO: 在此处添加构造函数逻辑
//
_items
=
new object
[
MessageHead_Length
]
;
}
protected struct KeyItemPair
{
public
object item;
public
string
key
;
public
KeyItemPair(string k,object obj)
{
key
=
k;
item
=
obj;
}
}
}
}
使用方法(方法不是很完整,可以继续扩展):
MessageHead MH
=
new MessageHead(
3
);
MH
[
"Confirm_NO"
]
=
"aaa";
MH
[
"IO_Seq"
]
=
"bbb";
MH
[
"Gross_Pack_NO"
]
=
"ccc";
注意:
Struct 的实现是在栈里面实现的
Class 实现是在托管堆里面实现的
Class里面的方法是在托管堆里面的方法表里面保存的.
此方法也可以用 Hashtable 来实现,具体实现将在以后进行研究
查看全文
相关阅读:
CloudFlare Workers 反代任意网站和挂载单页代码
排查Linux服务器是否有被入侵方法总结
修复Windows time时间服务无法自动启动的问题
如何删除windows服务
linux之NetHogs与nload流量监控
常用IPV4 DNS服务器与常用IPV6 DNS服务器
Win10系统如何删除网络及修改网络名称
window修改远程桌面RDP方法
单击鼠标右键菜单显示怎么在左边?
传统IDC机房部署网站
原文地址:https://www.cnblogs.com/jhtchina/p/261662.html
最新文章
ubuntu下cannot find lib....so.x 寻找动态链接库
js中substr、substring、slice的区别
js循环
js 中数字与字符串之间的转换
js中日期格式与时间戳格式互换
maven
win10蓝屏,windbg的使用
网络代码错误
sublime An unhandled OS error was encountered nodejspath_error
"Error: [$compile:multidir] Multiple directives
热门文章
解决UE4 Launcher启动速度极慢的方法
网站主导航三级菜单
网站banner常常要用到图片切换效果
模拟浏览器的滚动条,自己拿去美化
瀑布流布局的Js
制作简单的返回顶部按钮
显示隐藏搜索框的文字,高手不用看了
图片左右滚动,一次滚N个
新闻上下滚动效果,一次滚一个
解决360浏览器和谷歌(Google Chrome)浏览器下CSS设置字体大小小于12px无法生效的问题
Copyright © 2011-2022 走看看