Sum with Projection

   
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass {
    public static void Main() {
        string[] words = { "cherry", "apple", "blueberry" };

        double totalChars = words.Sum(w => w.Length);

        Console.WriteLine("There are a total of {0} characters in these words.", totalChars);
    }
}

    


use Linq Sum to sum an array

   
 


using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Reflection;

public class MainClass{
   public static void Main(){
            int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            var query = numbers.Sum();
   }
}

    


Use LINQ to SQL

   
 
using System;
using System.Linq;
using System.Data.Linq;
using System.Data.Linq.Mapping;

static class HelloLinqToSql {
    [Table(Name = "Contacts")]
    class Contact {
        [Column(IsPrimaryKey = true)]
        public int ContactID { get; set; }
        [Column(Name = "ContactName")]
        public string Name { get; set; }
        [Column]
        public string City { get; set; }
    }

    static void Main() {
        string path = System.IO.Path.GetFullPath("northwnd.mdf");
        DataContext db = new DataContext(path);

        var contacts =
          from contact in db.GetTable<Contact>()
          where contact.City == "Paris"
          select contact;

        foreach (var contact in contacts)
            Console.WriteLine("Bonjour " + contact.Name);
    }
}

    


Second SkipWhile Prototype

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass {
public static void Main() {
string[] presidents = {“ant”, “arding”, “arrison”, “Hayes”, “Hoover”, “ackson”};
IEnumerable items = presidents.SkipWhile((s, i) => s.Length > 4 && i < 10); foreach (string item in items) Console.WriteLine(item); } } [/csharp]