-4
using System;

namespace CardV5
{
    class Tee
    {
        private static int numOne = 4;
        private static int numTwo = 2;
        private static int numThree = 22;
        public int Value { get; set; }
        private int[, ,] m_tData = new int[numOne, numTwo, numThree];
        public int TeeData(int IndexOne, int IndexTwo, int IndexThree) 
        { 
            get{return m_tData[IndexOne, IndexTwo, IndexThree];}
            set{m_tData[IndexOne, IndexTwo, IndexThree] = Value;}
        }
    }
}

获取和设置是红线。错误标志:

只有赋值、调用、递增、递减、等待和新对象表达式可以用作语句。

如何解决这个问题?

4

3 回答 3

2

你有一个常规的方法:public int TeeData(int IndexOne, int IndexTwo, int IndexThree). getset符号用于属性,而不是方法。

我认为您想要的是索引属性 - 只需将括号更改为方括号,您将使用this而不是名称:

public int this[int IndexOne, int IndexTwo, int IndexThree]
{ 
    get{return m_tData[IndexOne, IndexTwo, IndexThree];}
    set{m_tData[IndexOne, IndexTwo, IndexThree] = Value;}
}

这将允许您执行以下操作:

Tee tee = new Tee();
tee[0,0,0] = /*something*/;
于 2013-10-01T22:41:28.090 回答
1

获取和设置适用于属性。在您的情况下,您已经定义了一个方法。Get\Set 在此上下文中无效

于 2013-10-01T22:41:41.250 回答
0

您可以创建单独的 get/set 属性:

    public int GetTeeData(int IndexOne, int IndexTwo, int IndexThree) 
    { 
        return m_tData[IndexOne, IndexTwo, IndexThree];
    }
    public void GetTeeData(int IndexOne, int IndexTwo, int IndexThree, int value) 
    { 
        m_tData[IndexOne, IndexTwo, IndexThree] = value;
    }

或使其成为索引器:

    public int this[int IndexOne, int IndexTwo, int IndexThree] 
    { 
        get{return m_tData[IndexOne, IndexTwo, IndexThree];}
        set{m_tData[IndexOne, IndexTwo, IndexThree] = Value;}
    }
于 2013-10-01T22:44:03.000 回答