2016-04-08 27 views
6

Ho un metodo che accetta una tabella hash e sto usando concat per aggiungerla alla fine di una tabella hash diverso, ma sto ottenendo questo errore:Aggiungi Hashtable alla fine di un altro Hashtable

The type arguments for method System.Linq.Enumerable.Concat<TSource>(this System.Collections.Generic.IEnumerable<TSource>, System.Collections.Generic.IEnumerable<TSource>)' cannot be inferred from the usage.

I don capisco bene cosa significa o cosa ho sbagliato Il mio metodo è il seguente:

public void resetCameras(Hashtable hashTable) 
{ 
    Hashtable ht = new Hashtable(); 

    ht.Add("time", 2.0f); 
    ht.Add("easeType","easeInOutQuad"); 
    ht.Add("onupdate","UpdateSize"); 
    ht.Add("from",size); 
    ht.Add("to",5.0f); 

    if(hashTable != null) { 
     ht = ht.Concat(hashTable); 
    } 

    iTween.ValueTo(gameObject,ht); 
} 

Spero che tu possa aiutare a spiegare il mio errore, ancora nuovo in C#.

+0

Quando si enumera una HashTable, si * solo * enumera le ** chiavi **. Fondamentalmente, LINQ ti sta dicendo che hai bisogno dei * valori * per le chiavi che stai 'concat''ing. – Tersosauros

+1

Si noti inoltre che HashTable/Dictionary non ha il concetto di ordine, quindi "aggiungi alla fine" non è un'operazione valida su questi tipi. –

+0

@Tersosauros quindi devo usare un ciclo for? In tal caso, non potrei usare semplicemente '.Add' per ogni chiave dell'altro? – WDUK

risposta

6

Sfortunatamente non esiste un modo semplice per merge/concat due HashTables, è necessario farlo in modo tradizionale con il ciclo di ogni voce.

foreach (DictionaryEntry entry in hashTable) 
{ 
    if(!ht.ContainsKey(entry.Key)) 
    { 
     ht.Add(entry.Key, entry.Value); 
    } 
} 

// rest of the logic