使用 IndexOf 方法查找第一个 @ 出现的位置与使用 LastlndexOf 方法查找 @ 在字符串中最后一次出现的位置相同即可
class Program
{
static void Main(string[] args)
{
string str = Console.ReadLine();
int firstIndex = str.IndexOf("@");
int lastIndex = str.LastIndexOf("@");
if(firstIndex != -1)
{
if (firstIndex == lastIndex)
{
Console.WriteLine("在该字符串中仅含有一个@");
}
else
{
Console.WriteLine("在该字符串中含有多个@");
}
}
else
{
Console.WriteLine("在该字符串中不含有@");
}
}
}