预期获取或设置访问者 - 我该如何解决这个问题?

时间:2015-05-26 17:04:53

标签: c#

private static IEnumerable<Image> Images
{
    get
    {
       return new Image
       {
          Resources.img1;
          Resources.img2;
          Resources.img3;
          Resources.img4;
          Resources.img5;
          Resources.img6;
          Resources.img7;
          Resources.img8;               
       };
    }
}<---here I get "} expected "- why?

2 个答案:

答案 0 :(得分:3)

您应该从getter返回图像集合,而不是单个Image对象。试试这个:

private static IEnumerable<Image> Images
{
    get
    {
        return new List<Image>
        {
            Resources.img1,
            Resources.img2,
            Resources.img3,
            Resources.img4,
            Resources.img5,
            Resources.img6,
            Resources.img7,
            Resources.img8               
        };
    }
}

答案 1 :(得分:2)

在列表初始化中使用符号;代替List<Image>。并按@Habib说的那样返回for (k, v) in myDict { println(k) }