asp.net 实现自定义Hashtable (.net)
程序员文章站
2024-03-11 16:06:01
需要两个类 1.typefiles.cs复制代码 代码如下:using system; namespace model { /// ///...
需要两个类
1.typefiles.cs
using system;
namespace model
{
/// <summary>
/// typefiles 的摘要说明。
/// </summary>
public class typefiles
{
private object _fkey;
private object _fvalue1;
private object _fvalue2;
public object fkey
{
get
{
return _fkey;
}
set
{
_fkey = value;
}
}
public object fvalue1
{
get
{
return _fvalue1;
}
set
{
_fvalue1 = value;
}
}
public object fvalue2
{
get
{
return _fvalue2;
}
set
{
_fvalue2 = value;
}
}
}
}
2.wehash.cs (hashtable 类, 与arraylist结合)
using system;
using system.collections;
namespace command
{
/// <summary>
/// wehash 的摘要说明。
/// </summary>
public class wehash
{
private arraylist alist = new arraylist();
public wehash()
{
//
// todo: 在此处添加构造函数逻辑
//
}
public void add(object key,object value,object valtype)
{
model.typefiles cmt=new model.typefiles();
cmt.fkey = key;
cmt.fvalue1 = value;
cmt.fvalue2 = valtype;
alist.add (cmt);
}
public arraylist hashitems
{
get
{
return alist;
}
set
{
alist = value;
}
}
public bool hascontaint(object key)
{
foreach(object itm in alist)
{
model.typefiles cmt = (model.typefiles)itm;
if (cmt.fkey.tostring() == key.tostring())
return true;
}
return false;
}
}
}
typefiles.cs 里可以多定义几个构造函数 (这样hash.add(项才可以多))
使用方法:
command.wehash cw=new wehash();
cw.add("keyname1","value1","value2");
cw.add("keyname2","value1","value2");
cw.add("keyname3","value1","value2");
然后再把 cw.hashitems 传给要操作的方即可.
要使.add添加个项更多,就要使得 typefiles.cs 构造多几个,然后再修改
public void add(object key,object value,object valtype)
{
model.typefiles cmt=new model.typefiles();
cmt.fkey = key;
cmt.fvalue1 = value;
cmt.fvalue2 = valtype;
....其余的cmt项.
alist.add (cmt);
}
1.typefiles.cs
复制代码 代码如下:
using system;
namespace model
{
/// <summary>
/// typefiles 的摘要说明。
/// </summary>
public class typefiles
{
private object _fkey;
private object _fvalue1;
private object _fvalue2;
public object fkey
{
get
{
return _fkey;
}
set
{
_fkey = value;
}
}
public object fvalue1
{
get
{
return _fvalue1;
}
set
{
_fvalue1 = value;
}
}
public object fvalue2
{
get
{
return _fvalue2;
}
set
{
_fvalue2 = value;
}
}
}
}
2.wehash.cs (hashtable 类, 与arraylist结合)
复制代码 代码如下:
using system;
using system.collections;
namespace command
{
/// <summary>
/// wehash 的摘要说明。
/// </summary>
public class wehash
{
private arraylist alist = new arraylist();
public wehash()
{
//
// todo: 在此处添加构造函数逻辑
//
}
public void add(object key,object value,object valtype)
{
model.typefiles cmt=new model.typefiles();
cmt.fkey = key;
cmt.fvalue1 = value;
cmt.fvalue2 = valtype;
alist.add (cmt);
}
public arraylist hashitems
{
get
{
return alist;
}
set
{
alist = value;
}
}
public bool hascontaint(object key)
{
foreach(object itm in alist)
{
model.typefiles cmt = (model.typefiles)itm;
if (cmt.fkey.tostring() == key.tostring())
return true;
}
return false;
}
}
}
typefiles.cs 里可以多定义几个构造函数 (这样hash.add(项才可以多))
使用方法:
command.wehash cw=new wehash();
cw.add("keyname1","value1","value2");
cw.add("keyname2","value1","value2");
cw.add("keyname3","value1","value2");
然后再把 cw.hashitems 传给要操作的方即可.
要使.add添加个项更多,就要使得 typefiles.cs 构造多几个,然后再修改
public void add(object key,object value,object valtype)
{
model.typefiles cmt=new model.typefiles();
cmt.fkey = key;
cmt.fvalue1 = value;
cmt.fvalue2 = valtype;
....其余的cmt项.
alist.add (cmt);
}
下一篇: javaweb实现在线支付功能