Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Hashtable to end of another Hashtable

Tags:

c#

I have a method which accepts a hashTable and i am using concat to add it to the end of a different hashTable, but i am getting this error:

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't fully understand what this means or what i got wrong. My method looks like this:

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);
}

Hope you can help explain my mistake, still new to C# .

like image 588
WDUK Avatar asked Apr 08 '16 03:04

WDUK


1 Answers

Unfortunately there is no easy way to merge/concat two HashTables, you have to do it in traditional way looping though each entry.

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

// rest of the logic
like image 185
Hari Prasad Avatar answered Oct 15 '22 01:10

Hari Prasad