using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace linq___
{
class Program
{
static void Main(string[] args)
{
int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 34, 56 };
//Through Linq
var traverse = from num in arr
where num > 4
select num;
foreach (var item in traverse)
{
Console.WriteLine(item);
}
//or
var tr = arr.Where((num) => num > 4);
foreach (var item in tr)
{
Console.WriteLine(item);
}
//or
var trr = arr.Where((num) => num.ToString().Length > 1);
foreach (var item in trr)
{
Console.WriteLine(item +"\t length greater than 1");
}
//Through for loop
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] > 4)
{
Console.WriteLine(arr[i]);
}
}
// Checking wheather the value is less than their index value
Console.WriteLine("\n checking of string");
String[] srr = { "zero", "one", "two", "three", "four", "five", "six" };
var check = srr.Where((digit, index) => digit.Length < index);
foreach (var item in check)
{
Console.WriteLine(item);
}
// Made by Jaspreet Singh
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace linq___
{
class Program
{
static void Main(string[] args)
{
int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 34, 56 };
//Through Linq
var traverse = from num in arr
where num > 4
select num;
foreach (var item in traverse)
{
Console.WriteLine(item);
}
//or
var tr = arr.Where((num) => num > 4);
foreach (var item in tr)
{
Console.WriteLine(item);
}
//or
var trr = arr.Where((num) => num.ToString().Length > 1);
foreach (var item in trr)
{
Console.WriteLine(item +"\t length greater than 1");
}
//Through for loop
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] > 4)
{
Console.WriteLine(arr[i]);
}
}
// Checking wheather the value is less than their index value
Console.WriteLine("\n checking of string");
String[] srr = { "zero", "one", "two", "three", "four", "five", "six" };
var check = srr.Where((digit, index) => digit.Length < index);
foreach (var item in check)
{
Console.WriteLine(item);
}
// Made by Jaspreet Singh
}
}
}
0 comments:
Post a Comment