Answer:
using System;
namespace ConsoleApp3
{
class Program
{
static void Main(string[] args)
{
double[] doubleArray = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 };
Console.WriteLine("Double Array values are:");
foreach (var b in doubleArray)
{
Console.WriteLine(b);
}
Console.WriteLine("Enter value to find position in Array");
var input = Console.ReadLine();
var value = Convert.ToDouble(input);
if (value == 99.0)
{
Environment.Exit(0);
}
try
{
var index = Array.IndexOf(doubleArray, value);
if (index == -1)
{
Console.WriteLine("Index was outside the bounds of the array");
Console.ReadLine();
}
else
{
Console.WriteLine("Position in Array is:" + index);
Console.ReadLine();
}
}
catch (Exception e)
{
Console.WriteLine("Index was outside the bounds of the array");
Console.ReadLine();
}
}
}
}
Step-by-step explanation:
this is the code of console program which initialize the double array from 1-10 and displays the existing values of array in console.
Then it will take input from user, convert it to double and find the value position in double array.
if 99, then program will be exist
if exist in array:display the index position
else:index was outside the bounds of the array in try catch block.