Find Max number from Array using C#.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Test_Application
{
public class Program
{
static void Main(string[] args)
{
int[] a = { 3, 8, 5, 9, 2, 0, 1 };
var k =a.Max();
Console.WriteLine(k);
Console.ReadLine();
}
}
}
Output :- 9.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Test_Application
{
public class Program
{
static void Main(string[] args)
{
int[] a = { 3, 8, 5, 9, 2, 0, 1 };
var k =a.Max();
Console.WriteLine(k);
Console.ReadLine();
}
}
}
Output :- 9.
Find Min number from Array using C#.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Test_Application
{
public class Program
{
static void Main(string[] args)
{
int[] a = { 3, 8, 5, 9, 2, 0, 1 };
var k =a.Min();
Console.WriteLine(k);
Console.ReadLine();
}
}
}
Output :- 0
Find n highest number from Array using Linq in C#
Third Higest number.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Test_Application
{
public class Program
{
static void Main(string[] args)
{
int j = 1;
int[] a = { 3, 8, 5, 9, 2, 0, 1 };
var k = (from i in a orderby i descending select i).Skip(3-j).First(); // increase skip position
Console.WriteLine(k);
Console.ReadLine();
}
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Test_Application
{
public class Program
{
static void Main(string[] args)
{
int[] a = { 3, 8, 5, 9, 2, 0, 1 };
var k =a.Min();
Console.WriteLine(k);
Console.ReadLine();
}
}
}
Output :- 0
Find n highest number from Array using Linq in C#
Third Higest number.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Test_Application
{
public class Program
{
static void Main(string[] args)
{
int j = 1;
int[] a = { 3, 8, 5, 9, 2, 0, 1 };
var k = (from i in a orderby i descending select i).Skip(3-j).First(); // increase skip position
Console.WriteLine(k);
Console.ReadLine();
}
}
}
Output :- 5