Asp.net implement custom hashtable (. NET)

Source: Internet
Author: User

Two classes are required.
1. typefiles. CS CopyCode The Code is as follows: using system;
Namespace Model
{
/// <Summary>
/// Summary of 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 the code is as follows: using system;
using system. collections;
namespace command
{< br> ///


// wehash summary.
//
public class wehash
{< br> private arraylist alist = new arraylist ();
Public wehash ()
{< br> //
// todo: add the constructor logic
//
}< br> Public void add (Object key, object value, object valtype)
{< br> model. typefiles CMT = new model. typefiles ();
cmt. fkey = key;
cmt. fvalue1 = value;
cmt. fvalue2 = valtype;
alist. add (CMT);
}< br> Public arraylist hashitems
{< br> Get
{< br> return alist;
}< br> set
{< br> alist = value;
}< BR >}< br> Public bool hascontaint (Object key)
{< br> foreach (Object ITM in alist)
{< br> model. typefiles CMT = (model. typefiles) ITM;
If (CMT. fkey. tostring () = key. tostring ()
return true;
}< br> return false;
}< BR >}

typefiles. several constructors can be defined in CS (such as hash. add (multiple items)
usage:
command. wehash CW = new wehash ();
CW. add ("keyname1", "value1", "value2");
CW. add ("keyname2", "value1", "value2");
CW. add ("keyname3", "value1", "value2");
. send hashitems to the operator.
to enable. add to add more items, you need to make typefiles. CS constructs several more parts, and then modifies
Public void add (Object key, object value, object valtype)
{< br> model. typefiles CMT = new model. typefiles ();
cmt. fkey = key;
cmt. fvalue1 = value;
cmt. fvalue2 = valtype;
.... other 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.