C#

Lambda

int Array

Math.Abs

using System;
using System.Linq;
*// Step 1: create array.*
int[] array1 = { 1, -1, -2, 0 };
*// Step 2: use simple Max to find maximum number.*
Console.WriteLine(array1.Max());
*// Step 3: find maximum number when all numbers are made positive.*
Console.WriteLine(array1.Max(element => Math.Abs(element)));1
2

Array

List

using System;
using System.Linq;
int[] array1 = { 1, -1, 2, 0 };
*// Part 1: find minimum number.*
Console.WriteLine(array1.Min());
*// Part 2: find minimum number when all numbers are made negative.*
Console.WriteLine(array1.Min(element => -element));-1
-2

Math.Max, Math.Min

Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.

Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.

This page was last updated on Apr 25, 2023 (rewrite).