以下代码中的输出错误 [英] Error in output in following code
问题描述
课程计划
{
static void Main(string [] args)
{
List< string> list = new List< string>();
list.Add(Amit);
list.Add(Raj);
list.Add(prem);
list.Add(Ram);
list.Add(pa);
foreach(字符串在列表中)
{
Console.WriteLine(s);
}
Console.WriteLine(list.Capacity);
Console.WriteLine(输入要搜索的名称:\ t);
string a = Convert .ToString(Console.ReadLine());
int b = list.BinarySearch(a);
Console.WriteLine(b);
if(b> = 0)
{
Console.WriteLine(List包含名称);
}
else
{
Console.WriteLine(List is NOT contains t他命名为);
}
Console.ReadLine();
}
}
显示输出:
Amit
Raj
Prem
Ram
pa
8
输入您要搜索的名称:
pa
-2
列表不包含名称
请建议关于这个错误的一些事情,因为该字符串已经在列表中
解释错误.....请
class Program
{
static void Main(string[] args)
{
List<string> list = new List<string>();
list.Add("Amit");
list.Add("Raj");
list.Add("prem");
list.Add("Ram");
list.Add("pa");
foreach (string s in list)
{
Console.WriteLine(s);
}
Console.WriteLine(list.Capacity);
Console.WriteLine("Enter the name which you want to search: \t");
string a = Convert.ToString(Console.ReadLine());
int b = list.BinarySearch(a);
Console.WriteLine(b);
if (b >= 0)
{
Console.WriteLine("List is contains the Name");
}
else
{
Console.WriteLine("List is NOT contains the Name");
}
Console.ReadLine();
}
}
shows output:
Amit
Raj
Prem
Ram
pa
8
Enter the name which you want to search:
pa
-2
List is NOT contain the name
Please suggest some thing about this erro because that string is already in the list
explain the error.....Please
推荐答案
请参阅: http://msdn.microsoft.com/en-us/ library / ftfdbfx6.aspx [ ^ ]
See: http://msdn.microsoft.com/en-us/library/ftfdbfx6.aspx[^]
列表< t>必须已根据比较器实现进行排序;否则,结果不正确。
The List<t> must already be sorted according to the comparer implementation; otherwise, the result is incorrect.
您在搜索之前忘记对列表进行排序。
And you have forget to sort the list before searching.
这篇关于以下代码中的输出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!