ПРОБЛЕМА: Я пытаюсь получить доступ к двоичным записям, которые были созданы в Borland Delphi и сохранены в базе данных SQL Server (как BLOB).
Q: Какая черта является синтаксисом для доступа к двухмерному массиву в С#?
Вот пример:
const
MAX_BOWLERS = 8;
gMAX_FRAMES = 40;
...
type
TFrame = Record Balls : array[1..3] of ShortInt; // Pins standing: balls 1, 2 and 3 Pins : array[1..3] of ShortInt; CurrentBall : Byte; Score : Integer; // Current score (-1= undefined) Attributes : TFrameAttributes; ...
TFrames = Array[1..Max_Bowlers, 0..gMax_Frames] of TFrame;
TgameRec = Record Side : Byte; Bowlers : tBowlers; Frames : TFrames; ...
Soooooooo....
Я успешно получил действительный "GameRec" для С# -land.
Я хочу получить доступ к GameRec.Frames [iBowler, iFrame].
Q: Как определить тип С# "TFrames = Array [1..Max_Bowlers, 0..gMax_Frames] из TFrame;" так что я могу это сделать?
Спасибо вам заблаговременно. PSM
Я нашел решение:
Рассматривайте двухмерный массив как свою собственную структуру, содержащую массив.
Содержит массив 1D, состоящий из элементов cols * rows
Предоставить индексированное свойство С#, чтобы внешние клиенты могли обращаться к элементам так, как если бы они находились в двухмерном массиве (что в плане макета памяти на самом деле есть!)
// C# Definition for Delphi 2-D array
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public unsafe struct TFrames
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst=(MAX_BOWLERS)*(gMAX_FRAMES+1))]
private TFrame[] row;
public TFrame this[int iBowler, int iFrame]
{
get
{
int ioffset = (iBowler * (gMAX_FRAMES+1)) + iFrame;
return row[ioffset];
}
}
}
// C# client example
public static string ConvertSplitToString(TgameRec currentGame, int iBowler)
{
StringBuilder sb = new StringBuilder();
TFrames frames = currentGame.frames;
for (int iFrame = 0; iFrame < 10; iFrame++)
{
if (frames[iBowler, iFrame].fSplit != 0)
sb.Append('.');
else
sb.Append(' ');
}
return sb.ToString ();
}