Advertisement
gabi11

Functional Programming - 2. Sum Numbers

May 25th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.59 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7.  
  8. namespace CSharpAdvanced
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             var input = Console.ReadLine();
  15.  
  16.             Func<string, int> change = x => int.Parse(x);
  17.  
  18.             var numbers = input.Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries)
  19.               .Select(change)
  20.               .ToArray();
  21.  
  22.             Console.WriteLine(numbers.Length);
  23.             Console.WriteLine(numbers.Sum());
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement