Convert Pascal 'type to C #

I am trying to convert a Pascal type to C #. I looked at Google, but I couldn’t find the answer, perhaps because I was looking incorrectly, so sorry if this is a duplicate.

I have two types of Pascal:

type
  TVector3i = array [0..2] of longint;

  Tcolface = packed record
    A, B, C: word;
    SurfaceA, SurfaceB: word;
  end;

I know

Tcolface = packed record
  A, B, C: word;
  SurfaceA, SurfaceB: word;
end;

converted to:

struct Tcolface {
  ushort A, B, C;
  ushort SurfaceA, SurfaceB;
}

but how to TVector3i = array [0..2] of longint;convert?

I try to avoid using / writing the class, since when I convert the rest of the Pascal code, it will expect the type as an array, and I try not to convert it to .xy and. g.

I really did float[] variablename = new float[3];, but as soon as I get it List<float[]> variblename, it gets a little harder.

Full code:

TVector3i = array [0..2] of Longint;
TVector3f = array [0..2] of Single;
TVector3d = array [0..2] of Double;

TVector4i = array [0..3] of Longint;
TVector4f = array [0..3] of Single;
TVector4d = array [0..3] of Double;

TMatrix3i = array [0..2] of TVector3i;
TMatrix3f = array [0..2] of TVector3f;
TMatrix3d = array [0..2] of TVector3d;

TMatrix4i = array [0..3] of TVector4i;
TMatrix4f = array [0..3] of TVector4f;
TMatrix4d = array [0..3] of TVector4d;

Therefore, why am I trying to avoid classes: D

+4
source share
2 answers

TVector3i = array [0..2] of longint; ?

. TVector3i . # . , , struct, int[] , [] indexer Pascal :

struct TVector3i
{
    private int[] arr = new int[3];

    public int this[int i]
    {
        get
        {
            return arr[i];
        }
        set
        {
            arr[i] = value;
        }
    }
}

: - :

struct TVector3<T>
{
    private T[] arr = new T[3];

    public T this[int i]
    {
        get
        {
            return arr[i];
        }
        set
        {
            arr[i] = value;
        }
    }
}

struct TVector4<T>
{
    private T[] arr = new T[4];

    public T this[int i]
    {
        get
        {
            return arr[i];
        }
        set
        {
            arr[i] = value;
        }
    }
}

using TVector3i = TVector3<int>;
using TVector3f = TVector3<float>;
using TVector3d = TVector3<double>;

using TVector4i = TVector4<int>;
using TVector4f = TVector4<float>;
using TVector4d = TVector4<double>;

using TMatrix3i = TVector3<TVector3i>;
using TMatrix3f = TVector3<TVector3f>;
using TMatrix3d = TVector3<TVector3d>;

using TMatrix4i = TVector4<TVector4i>;
using TMatrix4f = TVector4<TVector4f>;
using TMatrix4d = TVector4<TVector4d>;
+9

, . , , . , :

struct Vector3i
{
    int X;
    int Y;
    int Z;
}

, , . , [], .

+5

Source: https://habr.com/ru/post/1599386/


All Articles