Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
linqs
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { Program p = new Program(); p.linq7(); } public void linq7() { int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; var numsInPlece = numbers.Select((num, index) => new {Num = num, InPlace = (num == index)}); Console.WriteLine("Numbers in place"); foreach(var n in numsInPlece) { Console.WriteLine("{0}:{1}", n.Num, n.InPlace); } } public void linq6() { int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; string[] digitsName = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; var result = from n in numbers select new {digit = digitsName[n], Even= ((n % 2)==0)}; foreach(var d in result) { Console.WriteLine("Digit: {0} is {1}", d.digit, d.Even?"Even":"Odd"); } } public void linq5() { string[] fruts = { "aPPLE", "BlUeBeRrY", "cHeRry" }; var upperLowerWords = from w in fruts select new{ Upper = w.ToUpper(), lower = w.ToLower() }; foreach(var f in upperLowerWords) { Console.WriteLine("upper:{0}, lowercase:{1}", f.Upper, f.lower); } } public void linq4() { int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; string[] strings = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; var textNums = from n in numbers select strings[n]; Console.WriteLine("Number strings"); foreach(var s in textNums) { Console.WriteLine(s); } } public void linq3() { int [] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; var numsPlusOne= from n in numbers select n + 1; Console.WriteLine("Numbers plus 1"); foreach (var i in numsPlusOne) { Console.WriteLine(i); } } public void linq2() { String[] digits ={ "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; var shortDigits = digits.Where((digit, index) => digit.Length < index); var shortD = digits.Where((digit, index) => digit.Length < index); Console.WriteLine("Short digits:"); foreach (var x in shortD) { Console.WriteLine("The word {0} is shorter than its value", x); } } public void linq1() { int[] numbers = {1, 3, 4, 8, 9, 7, 4, 5, 6, 3, 2, 8, 10}; var lowNuns = from n in numbers where n < 5 select n; Console.WriteLine("Lower than 5"); foreach (var x in lowNuns) { Console.WriteLine(x); } var bigNums = from x in numbers where x >= 5 select x; Console.WriteLine("Gigger or equal than 5"); foreach(var x in bigNums) { Console.WriteLine(x); } } } }
run
|
edit
|
history
|
help
0
TEST 1
Fórum ➡ Using Regex to insert "item" tags into the unique "list" tag of an XML data ♦
Action<> usage example
C# Abstract class and method
Palindrome using stack
asxsdxsd
Hello
Find the value of a specific span in an html script
free robux
SHA Tester 2.0