using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSharpGitHubPgm
{
class Program
{
static void Main(string[] args)
{
int[] arr = {1,9,4,3};
Dictionary<string, int> storeDiffbetweenNumbers = new Dictionary<string, int>();
Console.WriteLine("To find the minimum difference between the array");
for (int i = 0; i < arr.Length; i++)
{
for (int j = i+1; j < arr.Length; j++)
{
int diff = arr[i] - arr[j];
string key = Convert.ToString(arr[i] +"-"+ arr[j]);
storeDiffbetweenNumbers.Add(key, diff);
}
}
var t = storeDiffbetweenNumbers.Where(x => x.Value > 0).Select(x => x).Min(x=>x.Value);
Console.WriteLine(t);
Console.ReadLine();
}
}
}In this code snippet you will learn how to Calculate the positive min difference between 2 values in a array using Dictionary.
