.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> LINQ >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Using Linq for Sum of an Integer Array.

Posted By:Hefin Dsouza       Posted Date: August 11, 2009    Points: 10    Category: LINQ    URL: http://www.dotnetspark.com  

Using Linq for Sum of an Integer Array.

This Code will let you know how to use the new LINQ Features to total the values given in an array.
This only works in Framework 3.5

        Dim nums() As Integer = {32, 33, 55, 77, 434, 233, 55, 7, 8, 9}
        Dim sum = nums.Sum()

        'Old Method
        Dim total As Integer = 0

        For Each n As Integer In nums
            total = total + n

        Console.WriteLine("The Sum of the Nums are : " & sum)
        Console.WriteLine("The Sum is : " & total)

Regards Hefin Dsouza


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend