SkipWhile with condition

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

public class MainClass{
public static void Main() {

            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
            
            var allButFirst3Numbers = numbers.SkipWhile(n => n % 3 != 0);
            
            Console.WriteLine("All elements starting from first element divisible by 3:");
            foreach (var n in allButFirst3Numbers) {
                Console.WriteLine(n);
            }
        }
}

    


SkipWhile with index

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

public class MainClass{
public static void Main() {

            int[] numbers = { 5, 4, 8, 6, 7, 2, 0 };
            
            var laterNumbers = numbers.SkipWhile((n, index) => n >= index);
            
            Console.WriteLine("All elements starting from first element less than its position:");
            foreach (var n in laterNumbers) {
                Console.WriteLine(n);
            }
        }

}

    


SkipWhile Prototype

image_pdfimage_print
   
 

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass {
    public static void Main() {

        string[] presidents = {"Ant", "arding", "arrison", "ayes", "Hoover", "ackson"};

        IEnumerable<string> items = presidents.SkipWhile(s => s.StartsWith("A"));

        foreach (string item in items)
            Console.WriteLine(item);
    }
}

    


Second SkipWhile Prototype

image_pdfimage_print

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]

Use LINQ to SQL

image_pdfimage_print
   
 
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);
    }
}

    


Use SkipWhile with index

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

public class MainClass{
   public static void Main(){
       int[] numbers = { 1, 3, 5, 4};
       var query = numbers.TakeWhile(( n, index) => n >= index);

       var query2 = numbers.SkipWhile(( n, index) => n >= index);
    }
}