Gets or sets the value associated with the specified key.[C#] In C#, this property is the indexer for the Hashtable class.[C#] public virtual object this[object key] {get; set;}Parameters [Visual Basic, C#, C++] key The key whose value to get or set.
Dim ha As New Hashtable ha.Add("col1", DateTime.Now) ha("col1")= Convert.ToDateTime(ha("col1")).ToShortDateString()
我贴段代码。看看能不能帮你!using System; using System.Collections;namespace ConsoleApplication1 { /// <summary> /// Summary description for Class1. /// </summary> class Class1 { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) { // // TODO: Add code to start application here // } } public interface Icon { object this[int index]{get;set;} object this[object key]{get;set;} void Add(object key,object value); void Remove(int index); void Remove(object key); bool Contain(object key); } public class Mycontain:Icon { private Hashtable mTable = new Hashtable(); #region Icon Members public object this[int index] { get { //use foreach to retrieve all the DictionaryEntry object in mTable, and then return it. int i = 0; foreach( DictionaryEntry _item in mTable ) { if ( i == index ) return mTable[ _item.Key ]; else i++; } return null; } set { //use foreach to retrieve all the DictionaryEntry object in mTable, and then set its value. int i = 0; foreach( DictionaryEntry _item in mTable ) { if ( i == index ) mTable[ _item.Key ] = value; else i++; } } } object ConsoleApplication1.Icon.this[object key] { get { if ( mTable.ContainsKey( key ) ) return mTable[ key ]; else return null; } set { // TODO: Add Mycontain.ConsoleApplication1.Icon.this setter implementation } } public void Add(object key, object value) { mTable.Add( key, value ); } public void Remove(int index) { //use foreach to retrieve all DictionaryEntry objects in mTable, and then remove it. foreach( DictionaryEntry _item in mTable ) { int i = 0; if ( i == index ) mTable.Remove( _item.Key ); else i++; } } void ConsoleApplication1.Icon.Remove(object key) { mTable.Remove( key ); } public bool Contain(object key) { return mTable.ContainsKey( key ); } #endregion } }
public virtual object this[object key] {get; set;}Parameters [Visual Basic, C#, C++]
key
The key whose value to get or set.
ha.Add("col1", DateTime.Now)
ha("col1")= Convert.ToDateTime(ha("col1")).ToShortDateString()
using System.Collections;namespace ConsoleApplication1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
}
} public interface Icon
{
object this[int index]{get;set;}
object this[object key]{get;set;}
void Add(object key,object value);
void Remove(int index);
void Remove(object key);
bool Contain(object key);
} public class Mycontain:Icon
{
private Hashtable mTable = new Hashtable(); #region Icon Members public object this[int index]
{
get
{
//use foreach to retrieve all the DictionaryEntry object in mTable, and then return it.
int i = 0;
foreach( DictionaryEntry _item in mTable )
{
if ( i == index )
return mTable[ _item.Key ];
else
i++;
}
return null;
}
set
{
//use foreach to retrieve all the DictionaryEntry object in mTable, and then set its value.
int i = 0;
foreach( DictionaryEntry _item in mTable )
{
if ( i == index )
mTable[ _item.Key ] = value;
else
i++;
}
}
} object ConsoleApplication1.Icon.this[object key]
{
get
{
if ( mTable.ContainsKey( key ) )
return mTable[ key ];
else
return null;
}
set
{
// TODO: Add Mycontain.ConsoleApplication1.Icon.this setter implementation
}
} public void Add(object key, object value)
{
mTable.Add( key, value );
} public void Remove(int index)
{
//use foreach to retrieve all DictionaryEntry objects in mTable, and then remove it.
foreach( DictionaryEntry _item in mTable )
{
int i = 0;
if ( i == index )
mTable.Remove( _item.Key );
else
i++;
}
} void ConsoleApplication1.Icon.Remove(object key)
{
mTable.Remove( key );
} public bool Contain(object key)
{
return mTable.ContainsKey( key );
} #endregion
}
}