none
LINQ - Aggregat - Wert um 1 erhöhen RRS feed

  • Frage

  • Hallo!

    Wie kann ich bei einer LINQ Abfrage den Wert abfragen und gleich um +1 erhöhen?
    Sorry. Ich bin noch in diesem Bereich Anfänger.

    Mein Beispiel:

    Dim resources = From ResourceItemExtern In ResourceItemListExtern
                            Select ResourceItemExtern.ResourceId, ResourceItemExtern.ResourceName,
    ResourceItemExtern.ResourceZeilenAnzeige
                            Distinct

    ResourceZeilenAnzeige  ... soll um +1 bei der Abfrage erhöht werden.

    Danke für die HILFE!

    Michael


    Mittwoch, 5. März 2014 09:08

Antworten

  • Hallo Michael

    	Private Class Test
    		Public Name As String
    		Public Count As Integer
    	End Class
    
    	Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
    		Dim lst As New List(Of Test)
    		Dim cTest As Test = Nothing
    		cTest = New Test With {.Name = "Hello", .Count = 1}
    		lst.Add(cTest)
    		cTest = New Test With {.Name = "World", .Count = 2}
    		lst.Add(cTest)
    		Dim result = From current In lst Select New With {current.Name, Key .count = IncCount(current)}
    		Console.WriteLine(result(0).count)
    		Console.WriteLine(lst(0).Count)
    	End Sub
    
    	Private Function IncCount(current As Test) As Integer
    		current.Count += 1
    		Return current.Count
    	End Function
    

    Gruß Scotty

    • Als Antwort markiert Michael-s-19 Mittwoch, 5. März 2014 12:03
    Mittwoch, 5. März 2014 10:09

Alle Antworten

  • Hallo Michael

    	Private Class Test
    		Public Name As String
    		Public Count As Integer
    	End Class
    
    	Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
    		Dim lst As New List(Of Test)
    		Dim cTest As Test = Nothing
    		cTest = New Test With {.Name = "Hello", .Count = 1}
    		lst.Add(cTest)
    		cTest = New Test With {.Name = "World", .Count = 2}
    		lst.Add(cTest)
    		Dim result = From current In lst Select New With {current.Name, Key .count = IncCount(current)}
    		Console.WriteLine(result(0).count)
    		Console.WriteLine(lst(0).Count)
    	End Sub
    
    	Private Function IncCount(current As Test) As Integer
    		current.Count += 1
    		Return current.Count
    	End Function
    

    Gruß Scotty

    • Als Antwort markiert Michael-s-19 Mittwoch, 5. März 2014 12:03
    Mittwoch, 5. März 2014 10:09
  • Vielen Dank!

    Gruß Michael

    Mittwoch, 5. März 2014 12:03