自定义一个数组,然后从屏幕输入一个数字,如果该数字存在该数组内,则输出该数字所在第几位(C#)

2025-05-23 14:05:39
推荐回答(1个)
回答1:

        static void Main(string[] args)
        {
            int[] temp = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            int tempId = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine((temp.ToList().IndexOf(tempId)) + 1);
            Console.ReadLine();
        }