質問

C#では、あなたは、プロパティをインデックス化していることはできません。いえ、私はC#2にVB.netから次のコードを変換する方法を教えてください。

Private _PatchSpectrum(49) As Double

Public ReadOnly  Property GetPatchSpectrum() As Double()
    Get
        Return _PatchSpectrum
    End Get
End Property

Public WriteOnly Default Property PatchSpectrum(idx As Integer) As Double
    Set(ByVal value as Double)
        _PatchSpectrum(idx) = value
    End Set
End Property
役に立ちましたか?

解決

あなたはこのようにしてください

private double[] _PatchSpectrum = new double[49]

public double[] GetPatchSpectrum
{
    get { return _PatchSpectrum; }
}

public double this[int index]
{
    set { this._PatchSpectrum[index] = value; }
}

他のヒント

やメソッドの代わりのプロパティを持つ:

double[] _patchSpectrum = new double[49];

public void SetPatchSpectrum(int index, double value) 
{
    _patchSpectrum[index] = value;
}

public double[] GetPatchSpectrum() 
{
    return _patchSpectrum;
}

を定義できインデクサにある、オブジェクト、上Listの作品のような方法のコレクションクラス。例えばます:

public double this[int i]
    {
        get
        {
            // This indexer is very simple, and just returns or sets
            // the corresponding element from the internal array.
            return _PatchSpectrum[i];
        }
        set
        {
            _PatchSpectrum[i] = value;
        }
    }

将来のコード変換はチェックアウトのために Telerikコードコンバータのます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top