asp.net 实现自定义Hashtable (.net)
时间:2022-02-07 10:11:29|栏目:.NET代码|点击: 次
需要两个类
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);
}
上一篇:Win2008 server + IIS7 设置身份模拟(ASP.NET impersonation)
栏 目:.NET代码
下一篇:C#实现验证码功能
本文标题:asp.net 实现自定义Hashtable (.net)
本文地址:http://www.codeinn.net/misctech/192692.html