0

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.

3
  • 5
    It's not at all clear what you mean by "entry1->string". Your whole question is basically unclear, I'm afraid. Commented Oct 5, 2011 at 15:39
  • Are you saying that each entry in the list would have a String and also another List? Commented Oct 5, 2011 at 15:42
  • entry2->string? That's not C#, that's C++. Commented Oct 5, 2011 at 15:49

2 Answers 2

4

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);
Sign up to request clarification or add additional context in comments.

2 Comments

How would you add an item to this? mylinkedlist.addlast(?)
Ha i do, i just can't figure out what the parameters should be, addlast("str1", list) won't work. Looks like it is expecting a MyListItem, instead of variables.
1

You could also try this:

Dictionary<String,List<Something>>

1 Comment

I bet this is the thing he was looking for, but people from C++ tend to ignore the dictionary type :-P

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.