using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
public static void Main() {
var wordsA = new string[] { "c", "ap", "b" };
var wordsB = new string[] { "c", "ap", "b" };
bool match = wordsA.Equals(wordsB);
Console.WriteLine("The sequences match: {0}", match);
}
}
ASP.NET & Csharp (C#)
ASP.NET & Csharp (C#) , Here you can find my posts about .NET c# .
Use static method syntax to call the query operators.
using System;
using System.Collections.Generic;
using System.Linq;
public class MainClass {
public static void Main() {
string[] names = { "J", "P", "G", "Pa" };
IEnumerable<string> filtered = Enumerable.Where(names,n => n.Contains("a"));
IEnumerable<string> sorted = Enumerable.OrderBy(filtered, n => n.Length);
IEnumerable<string> finalQuery = Enumerable.Select(sorted,n => n.ToUpper());
}
}
Returning a Sequence of Ten Integers All With the Value Two
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass {
public static void Main() {
IEnumerable<int> ints = Enumerable.Repeat(2, 10);
foreach (int i in ints)
Console.WriteLine(i);
}
}
uses Repeat to generate a sequence that contains the number 7 ten times.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
public static void Main() {
var numbers = Enumerable.Repeat(7, 10);
foreach (var n in numbers) {
Console.WriteLine(n);
}
}
}
Calling the Range Operator
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass {
public static void Main() {
IEnumerable<int> ints = Enumerable.Range(1, 10);
foreach (int i in ints)
Console.WriteLine(i);
}
}
Use Generation Operators: Range
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
public static void Main() {
var numbers =
from n in Enumerable.Range(100, 50)
select new { Number = n, OddEven = n % 2 == 1 ? "odd" : "even" };
foreach (var n in numbers) {
Console.WriteLine("The number {0} is {1}.", n.Number, n.OddEven);
}
}
}
Return an Empty Sequence of Strings
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass {
public static void Main() {
IEnumerable<string> strings = Enumerable.Empty<string>();
foreach (string s in strings)
Console.WriteLine(s); Console.WriteLine(strings.Count());
}
}