已定义了一个名为“this”的具有相同参数类型的成员错误

SAPBO 2010-07-04 06:33:57
谢谢各位
这个怎么修改啊。

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;
}
}
}
...全文
388 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
幻想多巴胺 2010-07-05
  • 打赏
  • 举报
回复

根据参数
dancingbit 2010-07-05
  • 打赏
  • 举报
回复
这些索引器只能保留一个,要不就要改变下标的类型。
兔子-顾问 2010-07-05
  • 打赏
  • 举报
回复
你还没明白么?
看看函数重载是如何定义的。
索引器是特殊的函数。支持重载,但要遵循重载的规则。
如果说有这样一个方法的重载:
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]的索引器,系统怎么知道如何返回呢?
SAPBO 2010-07-05
  • 打赏
  • 举报
回复
顶起,求助
SAPBO 2010-07-05
  • 打赏
  • 举报
回复
有朋友说:
c#不支持这样的语法
刚才试了一下,c++\cli可以支持
SAPBO 2010-07-04
  • 打赏
  • 举报
回复
上面的代码是Reflector.exe反编译过来的。只是这看不明白。
或者修改为
private static string m_FtEnabled = "" ;
public static bool FtEnabled
{
get
{
return m_FtEnabled;
}
}

只是这里要加入 [int Index]

如何操作?

谢谢
SAPBO 2010-07-04
  • 打赏
  • 举报
回复
上面的代码是Reflector.exe反编译过来的。只是这看不明白。
或者修改为
private static string m_FtEnabled = "" ;
public static bool FtEnabled
{
get
{
return m_FtEnabled;
}
}

只是这里要加入 [int Index]

如何操作?

谢谢

wuyq11 2010-07-04
  • 打赏
  • 举报
回复
一个类可以有多个索引器
public string this[int pos]
{
...
}
public string this[string data]
{
...
}
重载索引器
兔子-顾问 2010-07-04
  • 打赏
  • 举报
回复
基础问题。函数重载是怎么定义的?是根据返回值不同来定义的么?还是根据参数不同?估计楼主也是懂什么叫函数重载的,偶尔一时糊涂。^_^

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧