【发布时间】:2013-08-01 21:27:14
【问题描述】:
以下是我正在使用的一些代码;它将方法添加到内置类型以查找数组中元素的索引(如果它在数组中)。 我遇到的问题是 char[].IndexOf 方法的代码有效,但我的 string[,] 新代码无效。
string[,].IndexOf(来自变量的字符串, int x,int y);
显示错误: 'System.Array.IndexOf(int[], int, int)' 的最佳重载方法匹配有一些无效参数 论点 1:无法从 'string' 转换为 'int[]'
我不明白问题出在哪里。我已经定义了获取字符串而不是整数数组的方法,并且该类型没有内置 IndexOf 函数。
代码摘录:(希望不是确切的代码)
Using Extensions;
namespace one
{
class Form
private static char[] Alp = {'s','f'};
private method1
{
int pos = Alp.IndexOf(char[x]);
}
private method2
{
string[,] theory = table of letters
theory.IndexOf(string_array[0], x, y);
}
namespace Extensions
{
public static class MyExtensions
{
//Add method IndexOf to builtin type char[] taking parameter char thing
public static int IndexOf(this char[] array, char thing)
{
for (int x = 0; x < array.Length; x++)
{
char element = array[x];
if (thing == element) { return x; }
}
return -1;
}
public static void IndexOf(this string[,] array, string find, ref int x, ref int y)
{
}
}
}
【问题讨论】:
标签: c# multidimensional-array extension-methods invalid-argument