我为我的 Channel 对象列表 List<Channel> list
创建了一个名为 getByName 的扩展方法其中每个 channel 都有一个名称。
有没有办法通过写 list["Channel Name"]
来获取 channel 项目?而不是输入 list.getByName("Channel Name")
?
最佳答案
你需要一个像这样的索引器方法
public Channel this[string name]
{
get
{
return getByName(name);
}
}
关于c# - 在 C# 中更改或添加列表的索引类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51436196/