请问如何改变Hashtable中的值呀?Hashtable现在的值是 日期型 2005-5-20 10:37:53 我想一一把 日期格式转变为 2005-5-20 

解决方案 »

  1.   

    ((DateTime)value).ToShortTime()value 是Hashtable中的值
      

  2.   

    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. 
      

  3.   

    Dim ha As New Hashtable
    ha.Add("col1", DateTime.Now)
    ha("col1")= Convert.ToDateTime(ha("col1")).ToShortDateString()
      

  4.   

    我是将 datareader 里的长日期 给Hashtable 的索引的... 但现在需要Hashtable里的索引为短日期这样为什么不行呀?datalist是HashtableDataList[((DateTime)DateReader["atc_update"]).ToShortDateString()] = DateReader["atc_update"];大家都会有得分...忘解惑
      

  5.   

    楼主要实现什么功能啊?为什么要这样写?  --DataList[((DateTime)DateReader["atc_update"]).ToShortDateString()] 很迷惑哦. 为什么不用更简单的方法呢?直接用int编号不好么?还有.索引的key不能更改.只能改value.
      

  6.   

    补充一句:HashTable的键必须是唯一的
      

  7.   

    我贴段代码。看看能不能帮你!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
    }
    }