문제

C#에서는 인덱스 속성을 가질 수 없습니다. 즉, vb.net에서 c#으로 다음 코드를 어떻게 변환합니까?

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