:내가 F 번호에 다음 C#으로 변환하기 위해 노력하고있어
type Matrix(sourceMatrix:double[,]) =
let mutable (matrix:double[,]) = Array2D.create (sourceMatrix.GetUpperBound(0) + 1) (sourceMatrix.GetUpperBound(1) + 1) 0.0
member this.Item
with get(x, y) = matrix.[(x, y)]
and set(x, y) value = matrix.[(x, y)] <- value
do
for i = 0 to matrix.[i].Length - 1 do
for j = (i + 1) to matrix.[j].Length - 1 do
this.[i].[j] = matrix.[i].[j]
내 타입이 위 갖고있는 것 같아요 :
public class Matrix
{
double[,] matrix;
public int Cols
{
get
{
return this.matrix.GetUpperBound(1) + 1;
}
}
public int Rows
{
get
{
return this.matrix.GetUpperBound(0) + 1;
}
}
public Matrix(double[,] sourceMatrix)
{
this.matrix = new double[sourceMatrix.GetUpperBound(0) + 1, sourceMatrix.GetUpperBound(1) + 1];
for (int r = 0; r < this.Rows; r++)
{
for (int c = 0; c < this.Cols; c++)
{
this[r, c] = sourceMatrix[r, c];
}
}
}
public double this[int row, int col]
{
get
{
return this.matrix[row, col];
}
set
{
this.matrix[row, col] = value;
}
}
}
이것은 내가 지금까지 무엇을 가지고 두 가지 문제를 해결하는 방법을 모르겠습니다. 첫 번째 것은 그 행렬입니다. [(x, y)]는 유형이`a []이지만 double 형 [,]을가집니다. 두 번째 유형 정의에는 구성원 및 인터페이스 정의 앞에 let/do 바인딩이 있어야합니다. 문제는 do 블록에서 인덱스 된 속성을 채우려고한다는 것입니다. 즉, 먼저이를 만들어야한다는 의미입니다. 사전에
감사합니다,
밥 첫 번째 문제에 관해서는
미안 해요, 난 그냥 그것을 편집 붙여 넣기 : 당신은 당신의 코드를보다 직역을 원하는 경우
그러나, 당신은 당신의 새로 건설 된 예에게 (이 경우
this
)의 이름을 제공 할 수 있습니다 잘못된 생성자에서. – Beaker우수 답변 및 귀하의 올바른 가정이었던 읽기 전용 캐치. 원래 C#은 제 것이 아니었고 저는 그것을 간과했습니다. C#과 F # 모두 잘하는 것이 좋을 것입니다. :) – Beaker
관심있는 사람이 있으면 후속 질문을 추가했습니다. http://stackoverflow.com/questions/5212570/adding-overloaded-constructors-to-implicit-f-type – Beaker