索引问题!!怎么出错了

[复制链接]
查看11 | 回复1 | 2009-7-5 19:22:30 | 显示全部楼层 |阅读模式
namespace ConsoleApplication18
{

class MM

{

private string a;

private string b;

public MM(string a,string b)

{

this.a=a;

this.b=b;

}

public string A

{

get { return a; }

set { a = value; }

}

public string B

{

get { return b; }

set { b = value; }

}

}

class jia

{

MM[] arr = new MM[100];

int pos = 0;

public void Add(string a, string b)

{

arr[pos] = new MM(a,b);

pos++;

}

public string this[string b]

{

get

{

for (int i = 0; i <arr.Length; i++)

if (arr.B == b)

return arr.A;

}

}

}

class Program

{

static void Main(string[] args)

{

jia q = new jia();

q.Add("asd","123");

q.Add("zxc","456");

Console.WriteLine(q["123"]);

}

}
}
根据b查找a
运行起来说get并非所有返回路径 索引里哪里错了

回复

使用道具 举报

千问 | 2009-7-5 19:22:30 | 显示全部楼层
public string this[string b]要求返回字符串你的get理只有arr.B == b时才返回再加个返回就行了...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行