C# 错误CS0411方法';二进制搜索(T[],T,IComparer)和x27;无法从用法中推断

C# 错误CS0411方法';二进制搜索(T[],T,IComparer)和x27;无法从用法中推断,c#,algorithm,interface,binary-search,C#,Algorithm,Interface,Binary Search,我不明白我做错了什么 我的二进制搜索方法收到此错误消息 错误CS0411方法的类型参数 无法推断“Program.Binary_搜索(T[],T,IComparer)” 从用法来看。尝试显式指定类型参数 //二进制搜索方法。 公共静态void二进制搜索(T[]数据) { 二进制搜索(数据,Console.ReadLine(),Comparer.Default); } //二进制搜索算法 公共静态整型二进制搜索(T[]数据,T searchFor,IComparercomparer) { in

我不明白我做错了什么

我的二进制搜索方法收到此错误消息

错误CS0411方法的类型参数 无法推断“Program.Binary_搜索(T[],T,IComparer)” 从用法来看。尝试显式指定类型参数

//二进制搜索方法。
公共静态void二进制搜索(T[]数据)
{
二进制搜索(数据,Console.ReadLine(),Comparer.Default);
}

//二进制搜索算法
公共静态整型二进制搜索(T[]数据,T searchFor,IComparercomparer)
{
int高、低、中;
高=数据。长度-1;
低=0;
//如果数组的第一个元素是我要查找的,那么返回该元素。
if(数据[0]。等于(搜索))
返回0;
//否则,如果数组中最高的元素是我要查找的项,则返回该元素。
else if(数据[high].Equals(搜索))
高回报;
其他的
{
当低点低于或等于高点时,中间点位于最高点和下端点的中间。
while(低0)
高=中-1;
//否则(当前中点低于搜索项)将新低点设置为当前中点+1。
其他的
低=中+1;
}
返回-1;
}
}

主程序

  static void Main(string[] args)
            {
                Console.WriteLine("Analysis of Seismic Data.\n");
                //Read in the files and put them into arrays.
                String[] Years = File.ReadAllLines(@"Data\Year_1.txt");
                String[] Months = File.ReadAllLines(@"Data\Month_1.txt");
                String[] Days = File.ReadAllLines(@"Data\Day_1.txt");
                String[] Times = File.ReadAllLines(@"Data\Time_1.txt");
                String[] Depths = File.ReadAllLines(@"Data\Depth_1.txt");
                String[] Latitudes = File.ReadAllLines(@"Data\Latitude_1.txt");
                String[] Longitudes = File.ReadAllLines(@"Data\Longitude_1.txt");
                String[] Magnitudes = File.ReadAllLines(@"Data\Magnitude_1.txt");
                String[] Regions = File.ReadAllLines(@"Data\Region_1.txt");
                String[] IRIS_IDs = File.ReadAllLines(@"Data\IRIS_ID_1.txt");
                String[] Timestamps = File.ReadAllLines(@"Data\Timestamp_1.txt");
        //Read in user's decision.
        Console.Write("Select which Collection is to be analysed: ");

        int collectionDecision = Convert.ToInt32(Console.ReadLine());

        //Selected which collection is to be analyzed
        switch (collectionDecision)
        {
            case 1:
                //Create another switch statement to select either ascending or descending sort.
                Console.WriteLine("\nWould you like to sort the Collection in Ascending or Descending order?");
                Console.WriteLine("1-Ascending");
                Console.WriteLine("2-Descending");
                int sortingDecision = Convert.ToInt32(Console.ReadLine());
                switch (sortingDecision)
                {
                    case 1:
                        //Using the default QuickSort option to sort the collection in an ascending order.
                        QuickSort(Years);
                        Console.WriteLine("Contents of the Ascending Year Collection: ");
                        foreach (var year in Years)
                        {
                            Console.WriteLine(year);
                        }
                        Console.WriteLine("\nEnter the Number/Name of the items you are looking for from the previously selected Collection.");
                        Console.Write("Search: ");
                        //How do I implement Binary Search here to search for specific items from a selected Array/Collection and display them?

                        break;
                    case 2:
                        //Using Comparer<T>.Create to create a custom object and change the algorithm to sort in a Descending order.
                        QuickSort(Years, Comparer<string>.Create((a, b) => b.CompareTo(a)));
                        Console.WriteLine("Contents of the Descending Year Collection: ");
                        foreach (var year in Years)
                        {
                            Console.WriteLine(year);
                        }
                        Console.WriteLine("\nEnter the Number/Name of the items you are looking for from the previously selected Collection.");
                        Console.Write("Search: ");
                        //How do I implement Binary Search here to search for specific items from a selected Array/Collection and display them?
                        break;

                }
                break;
static void Main(字符串[]args)
{
Console.WriteLine(“地震数据分析”。\n”);
//读入文件并将其放入数组。
String[]Years=File.ReadAllLines(@“Data\Year_1.txt”);
String[]Months=File.ReadAllLines(@“Data\Month_1.txt”);
String[]Days=File.ReadAllLines(@“Data\Day_1.txt”);
String[]Times=File.ReadAllLines(@“Data\Time_1.txt”);
字符串[]深度=File.ReadAllLines(@“Data\Depth_1.txt”);
String[]Latitudes=File.ReadAllLines(@“Data\Latitude_1.txt”);
字符串[]经度=File.ReadAllLines(@“Data\Longitude_1.txt”);
String[]magnities=File.ReadAllLines(@“Data\magnities_1.txt”);
String[]Regions=File.ReadAllLines(@“Data\Region_1.txt”);
字符串[]IRIS_ID=File.ReadAllLines(@“Data\IRIS_ID_1.txt”);
String[]Timestamp=File.ReadAllLines(@“Data\Timestamp_1.txt”);
//阅读用户的决定。
编写(“选择要分析的集合:”);
int collectionDecision=Convert.ToInt32(Console.ReadLine());
//选择要分析的集合
开关(收集决策)
{
案例1:
//创建另一个switch语句以选择升序或降序排序。
Console.WriteLine(“\n是否要按升序或降序对集合排序?”);
控制台写入线(“1-上升”);
控制台写入线(“2-下降”);
int-sortingDecision=Convert.ToInt32(Console.ReadLine());
开关(排序决策)
{
案例1:
//使用默认的快速排序选项以升序对集合进行排序。
快速排序(年);
Console.WriteLine(“上升年份集合的内容:”);
foreach(var年,以年为单位)
{
控制台写入线(年);
}
Console.WriteLine(“\n输入您正在从以前选择的集合中查找的项目的编号/名称。”);
控制台。写入(“搜索:”);
//如何在此处实现二进制搜索以从选定数组/集合中搜索特定项并显示它们?
打破
案例2:
//使用Comparer.Create创建自定义对象,并将算法更改为按降序排序。
快速排序(年份,比较器.Create((a,b)=>b.CompareTo(a));
Console.WriteLine(“下降年份集合的内容:”);
foreach(var年,以年为单位)
{
控制台写入线(年);
}
Console.WriteLine(“\n输入您正在从以前选择的集合中查找的项目的编号/名称。”);
控制台。写入(“搜索:”);
//如何在此处实现二进制搜索以从选定数组/集合中搜索特定项并显示它们?
打破
}
打破

我正在尝试制作一个应用程序,其中用户选择要搜索的数组,一旦选择了数组,用户将对数组进行排序,然后用户可以使用二进制搜索从数组中搜索特定项目。例如,如果用户在Years数组中,他们可以输入“2016”二进制搜索将从列表中搜索出所有2016项,并显示在控制台上。字符串数组包含不同的数据类型:整数、字符串、双精度。

这里是一个关于
二进制搜索方法如何处理字符串的快速示例:

public static void Main(string[] args)
{
    Console.WriteLine("Please enter a value to search:");

    var toSearch = Console.ReadLine();

    var strings = GetOrderedArrayOfStrings(); // assuming here we have an ordered string[]

    var position = Binary_Search(strings, toSearch, Comparer<string>.Default);

    if(position == -1)
        Console.WriteLine("Not found");
    else
        Console.WriteLine($"Found at position {position}");
}
publicstaticvoidmain(字符串[]args)
{
WriteLine(“请输入要搜索的值:”);
var-toSearch=Console.ReadLine();
var strings=GetOrderedArrayOfStrings();//假设我们
  static void Main(string[] args)
            {
                Console.WriteLine("Analysis of Seismic Data.\n");
                //Read in the files and put them into arrays.
                String[] Years = File.ReadAllLines(@"Data\Year_1.txt");
                String[] Months = File.ReadAllLines(@"Data\Month_1.txt");
                String[] Days = File.ReadAllLines(@"Data\Day_1.txt");
                String[] Times = File.ReadAllLines(@"Data\Time_1.txt");
                String[] Depths = File.ReadAllLines(@"Data\Depth_1.txt");
                String[] Latitudes = File.ReadAllLines(@"Data\Latitude_1.txt");
                String[] Longitudes = File.ReadAllLines(@"Data\Longitude_1.txt");
                String[] Magnitudes = File.ReadAllLines(@"Data\Magnitude_1.txt");
                String[] Regions = File.ReadAllLines(@"Data\Region_1.txt");
                String[] IRIS_IDs = File.ReadAllLines(@"Data\IRIS_ID_1.txt");
                String[] Timestamps = File.ReadAllLines(@"Data\Timestamp_1.txt");
        //Read in user's decision.
        Console.Write("Select which Collection is to be analysed: ");

        int collectionDecision = Convert.ToInt32(Console.ReadLine());

        //Selected which collection is to be analyzed
        switch (collectionDecision)
        {
            case 1:
                //Create another switch statement to select either ascending or descending sort.
                Console.WriteLine("\nWould you like to sort the Collection in Ascending or Descending order?");
                Console.WriteLine("1-Ascending");
                Console.WriteLine("2-Descending");
                int sortingDecision = Convert.ToInt32(Console.ReadLine());
                switch (sortingDecision)
                {
                    case 1:
                        //Using the default QuickSort option to sort the collection in an ascending order.
                        QuickSort(Years);
                        Console.WriteLine("Contents of the Ascending Year Collection: ");
                        foreach (var year in Years)
                        {
                            Console.WriteLine(year);
                        }
                        Console.WriteLine("\nEnter the Number/Name of the items you are looking for from the previously selected Collection.");
                        Console.Write("Search: ");
                        //How do I implement Binary Search here to search for specific items from a selected Array/Collection and display them?

                        break;
                    case 2:
                        //Using Comparer<T>.Create to create a custom object and change the algorithm to sort in a Descending order.
                        QuickSort(Years, Comparer<string>.Create((a, b) => b.CompareTo(a)));
                        Console.WriteLine("Contents of the Descending Year Collection: ");
                        foreach (var year in Years)
                        {
                            Console.WriteLine(year);
                        }
                        Console.WriteLine("\nEnter the Number/Name of the items you are looking for from the previously selected Collection.");
                        Console.Write("Search: ");
                        //How do I implement Binary Search here to search for specific items from a selected Array/Collection and display them?
                        break;

                }
                break;
public static void Main(string[] args)
{
    Console.WriteLine("Please enter a value to search:");

    var toSearch = Console.ReadLine();

    var strings = GetOrderedArrayOfStrings(); // assuming here we have an ordered string[]

    var position = Binary_Search(strings, toSearch, Comparer<string>.Default);

    if(position == -1)
        Console.WriteLine("Not found");
    else
        Console.WriteLine($"Found at position {position}");
}