已定义了一个名为“this”的具有相同参数类型的成员错误
谢谢各位这个怎么修改啊。
public class ClsCostType
{
// Fields
private static string[] m_FtEnabled = new string[0x20];
private static string[] m_FtName = new string[0x20];
private static string[] m_MaEnabled = new string[12];
private static string[] m_MaName = new string[12];
private static bool m_NeedRefresh = true;
// Methods
private static void Refresh()
{
//例子
if (m_NeedRefresh)
{
m_NeedRefresh=m_NeedRefresh ;
}
}
// Properties
public static bool this[int Index]
{
get
{
Refresh();
return (m_FtEnabled[Index] == "Y");
}
}
public static string this[int Index]
{
get
{
Refresh();
return m_FtName[Index];
}
}
public static bool this[int Index]
{
get
{
Refresh();
return (m_MaEnabled[Index] == "Y");
}
}
public static string this[int Index]
{
get
{
Refresh();
return m_MaName[Index];
}
}
public static bool NeedRefresh
{
get
{
return m_NeedRefresh;
}
set
{
m_NeedRefresh = value;
}
}
}
--------------------编程问答-------------------- 基础问题。函数重载是怎么定义的?是根据返回值不同来定义的么?还是根据参数不同?估计楼主也是懂什么叫函数重载的,偶尔一时糊涂。^_^ --------------------编程问答-------------------- 一个类可以有多个索引器
public string this[int pos]
{
...
}
public string this[string data]
{
...
}
重载索引器
--------------------编程问答-------------------- 上面的代码是Reflector.exe反编译过来的。只是这看不明白。
或者修改为
private static string m_FtEnabled = "" ;
public static bool FtEnabled
{
get
{
return m_FtEnabled;
}
}
只是这里要加入 [int Index]
如何操作?
谢谢
--------------------编程问答-------------------- 上面的代码是Reflector.exe反编译过来的。只是这看不明白。
或者修改为
private static string m_FtEnabled = "" ;
public static bool FtEnabled
{
get
{
return m_FtEnabled;
}
}
只是这里要加入 [int Index]
如何操作?
谢谢 --------------------编程问答-------------------- 顶起,求助 --------------------编程问答-------------------- 你还没明白么?
看看函数重载是如何定义的。
索引器是特殊的函数。支持重载,但要遵循重载的规则。
如果说有这样一个方法的重载:
string GetValue(int i) { return i.ToString();}
int GetValue(int i) { return i+1;}
long GetValue(int i) { return (long)(i+10);}
如果你不要返回值,直接是用:
GetValue(5);
此时你觉得系统应该执行哪一个呢?
你这也是一样。都是[int]的索引器,系统怎么知道如何返回呢? --------------------编程问答-------------------- 这些索引器只能保留一个,要不就要改变下标的类型。 --------------------编程问答--------------------
根据参数 --------------------编程问答-------------------- 有朋友说:
c#不支持这样的语法
刚才试了一下,c++\cli可以支持
补充:.NET技术 , C#