GodsCrimeScene
GodsCrimeScene

Reputation: 1270

Using LinkedList<> in C#

I am looking to use the C# Linked list class instead of creating my own, but I'm not sure how to stick multiple items in the LinkedList<>.

I would like to do something like LinkedList<string, List>, to allow me to have:

entry1->string

And also have a List:

entry2->string, and list

All I see online from tutorials it that it will allow LinkedList only,

Any ideas on how to get more than 1 value in my linked list? Thanks.

Upvotes: 0

Views: 845

Answers (2)

Erix
Erix

Reputation: 7105

I'm going to guess what you mean... You need to create a custom object for your list..

public class MyListItem
{
    public String s;
    public List<Something> list;
}

Then you can do

LinkedList<MyListItem> myLinkedList = new LinkedList<MyListItem>();

Now each item in your LinkedList has a String and a List.

You can add an item with something like

MyListItem myListItem = new MyListItem();
myListItem.s = "a string";
myListItem.list = someList;
myLinkedList.AddLast(myListItem);

Upvotes: 5

HitLikeAHammer
HitLikeAHammer

Reputation: 2695

You could also try this:

Dictionary<String,List<Something>>

Upvotes: 1

Related Questions