可以使用循环遍历数组,检查数组中的每个元素是否和用户输入的数值相等。若相等,则输出该元素的索引值,即序号。如果循环结束后仍然没有找到相等的元素,则输出"不存在"。 以下是一个示例代码:
```csharp
int[] array = new int[10] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
Console.Write("请输入一个数值:");
int userInput = Convert.ToInt32(Console.ReadLine());
bool found = false;
for (int i = 0; i < array.Length; i++)
{
if (array[i] == userInput)
{
Console.WriteLine("数值 {0} 的序号为 {1}", userInput, i + 1);
found = true;
break;
}
}
if (!found)
{
Console.WriteLine("不存在");
}
```
在上述示例中,我们先创建了一个包含十个数的数组,然后通过循环遍历数组来寻找用户输入的数值。如果找到了相等的数值,就输出该数值的序号;否则,输出"不存在"。