using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
decimal[] numbers = { 3, 4, 8 };
decimal sumTotal = numbers.Sum(); // 15
Console.WriteLine(sumTotal);
}
}
The output:
15
The following returns the total length of each of the strings in the names array:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
string[] names = { "Java", "C#", "Javascript", "SQL", "Oracle", "Python", "C++", "C", "HTML", "CSS" };
int combinedLength = names.Sum(s => s.Length); // 19
Console.WriteLine(combinedLength);
}
}
The output:
42
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |