Click here to Skip to main content
15,885,985 members
Articles / Programming Languages / Visual Basic

Cumulating values with LINQ

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
27 Jul 2012CPOL1 min read 10.9K   20   1  
This is an alternative for "Cumulating values with LINQ"
Imports CumulativeHelper

Module MainModule
    Sub Main()
        ' Array of test numbers
        Dim numbers As Decimal() = New Decimal() {1, 3, 5, 7, 11}

        ' Calculate and print the cumulative sum for the numbers
        System.Diagnostics.Debug.WriteLine("The cumulative sum contains the following results")
        For Each partialSum As Decimal In numbers.CumulativeSum()
            System.Diagnostics.Debug.WriteLine("   - {0}", partialSum)
        Next
        System.Diagnostics.Debug.WriteLine("The cumulative sum total is {0}", numbers.CumulativeSum().Last())

        ' Some random path
        Dim somePath As String = "C:\Some directory\Some subdirectory\Somefile.txt"

        ' Split the path and print out each cumulated portion of the path
        System.Diagnostics.Debug.WriteLine("The path contains the following parts")
        For Each partialPath As String In somePath.Split("\").CumulativePath()
            System.Diagnostics.Debug.WriteLine("   - '{0}'", New Object() {partialPath})
        Next

        ' Some partially existing path
        Dim somePath2 As String = "C:\Windows\Some non-existent directory\Some non-existent file.txt"

        ' Split the path and print out each cumulated portion of the path
        System.Diagnostics.Debug.WriteLine("The path parts are valid as follows")
        For Each partialPath As String In somePath2.Split("\").AllButLast().CumulativePath()
            System.Diagnostics.Debug.WriteLine("   - '{0}' does exist: {1}", partialPath, System.IO.Directory.Exists(partialPath))
        Next
    End Sub
End Module

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Europe Europe
Biography provided

Comments and Discussions