asp.net implement custom Hashtable (. net) _ Practical Tips

Source: Internet
Author: User
Requires two classes
1. TypeFiles.cs
Copy Code code as follows:

Using System;
Namespace Model
{
<summary>
Summary description of the 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 class, combined with ArrayList)
Copy Code code as follows:

Using System;
Using System.Collections;
Namespace Command
{
<summary>
Summary description of the Wehash.
</summary>
public class Wehash
{
Private ArrayList alist = new ArrayList ();
Public Wehash ()
{
//
TODO: Add constructor logic here
//
}
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;
}
}
}

Several constructors can be defined in the TypeFiles.cs (so that hash.add can be more)
How to use:
Command.wehash cw=new Wehash ();
cw. ADD ("KeyName1", "value1", "value2");
cw. ADD ("KeyName2", "value1", "value2");
cw. ADD ("KeyName3", "value1", "value2");
And then the CW. Hashitems is passed to the party to be manipulated.
To make. Add more items, you need to make TypeFiles.cs constructs a few more, and then modify
public void Add (object key,object value,object valtype)
{
Model.typefiles cmt=new model.typefiles ();
Cmt. Fkey = key;
Cmt. Fvalue1 = value;
Cmt. Fvalue2 = Valtype;
.... The remaining CMT items.
Alist. ADD (CMT);
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.