views:

29

answers:

1

hello,

i want to use an List to store the title, path,... from Documents.

I declared the list like this: Dim MyDocuments As New List(Of Document)

But i don't really know how to handle the list. i want to use the list instead of an ReDim Array.

For i = 0 To results - 1 Step 1 ' forschleife zum durchlaufen der Ergebnisse

                            Try


                                MyDocuments.Add(New Document())


                                array_results(i, 0) = hits.Doc(i).Get("title")
                                array_results(i, 0) += hits.Doc(i).Get("doc_typ") 
                                array_results(i, 1) = hits.Doc(i).Get("pfad")
                                'array_results(i, 2) = hits.Doc(i).Get("date_of_create") '
                                array_results(i, 2) = hits.Doc(i).Get("last_change")
                                array_results(i, 3) = CStr(hits.Score(i))
                                array_results(i, 4) = hits.Doc(i).Get("doc_typ")

Can I store the object Document, or do i have to create an own class?? Is there a good tutorial for using the list? (i searched, but didn't found something good) Is the List of (T) the right data structure?

but how can i do like mylist(i) ->gettitle() or something like this?

thanks in advance!

A: 

Yes, you can store your documents in a generic List. Deciding if a List<T> is the right data structure or not depends on what you want to do with it. Maybe if you provide more information someone could come up with a better example. I don't know VB.NET so i'll do it in C#.

// i assume you're using the Document class of Lucene.NET
List<Document> documents = new List<Document>();   

// add the documents to your collection
for (i = 0; i < hits.Length(); i++)
{
    // each result in the list contains a Document 
    // which you can add to your list
    documents.Add(hits.Doc(i));   
}

// you can search the list for a Document following a specific rule, using lambda expressions
Document myDoc = documents.Find(d => d.Get("title") == "a value");

// you can get a document by a specific index
Document myOtherDoc = documents[0];

// you can search the list for multiple Documents following a specific rule, using lambda expressions
List<Document> myDocs = documents.FindAll(d => d.Get("doc_typ") == "a type");

More information about the List<T> can be found here: http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx

More information on lambda expressions can be found here: http://msdn.microsoft.com/en-us/library/bb397687.aspx

This article on SO shows how to use lambdas to search a List<T>

devnull
thank you, you're answer is very very helpfull !
tim
but how do i know, that the right Document is chosen?what does "documents.Add(new Document());" exactly do? do i have to declare somewhere what the "new Document" is?
tim
i updated my answer to match your scenario
devnull
great, thank you a lot!
tim