netmajor
netmajor

Reputation: 6585

Add generic collection to LinkedList problem

I have collection:

 class HashedData : IComparable
{
    string key;

    public string Key
    {
        get { return key; }
        set { key = value; }
    }
    string value;

    public string Value
    {
        get { return this.value; }
        set { this.value = value; }
    }


    public int CompareTo(object obj)
    {
        if (obj is HashedData)
        {
            HashedData hd = (HashedData)obj;
            return this.Key.CompareTo(hd.Key);
        }
        throw new NotImplementedException("Obiekt nie jest typu HashData");
    }
}

and method which use this collection as type od LInkedList:

        public void AddToHashTable(List<LinkedList<HashedData>> tablicaHashująca, HashedData data)
    {
        tablicaHashujaca[this.Hashuj(data.Key)].AddLast(**data**);
    }

I have error:

Error 1 The best overloaded method match for 'System.Collections.Generic.LinkedList.AddLast(string)' has some invalid arguments

Error 2 Argument 1: cannot convert from 'Hashowanie.HashedData' to 'string'

But why can't I add HashData object to LinkedList? It's any way to do this ?

Upvotes: 0

Views: 293

Answers (2)

TalentTuner
TalentTuner

Reputation: 17556

i am able to do it , if you define LinkedList < HashedData> then when you call AddLast , it will let you add the object of HashedData in the LinkedList.

i don't see any problem, can you please post more code

Upvotes: 2

leppie
leppie

Reputation: 117240

data.Value

Not sure if that is what you want.

Upvotes: 0

Related Questions