Autor Beitrag
Baumunk
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 50

WinXP
Delphi 2005
BeitragVerfasst: Di 28.11.06 14:39 
Hallo,

Mal wieder anfeänger frage.

Wie deklarie ich folgendes Typ, der in Delphi so zu delkarieren ist:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
type
  RGBArray = array[0..2of Byte;

var
  B: array of RGBArray;


in c# ?

voraus danke
Robert_G
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 416


Delphi32 (D2005 PE); Chrome/C# (VS2003 E/A, VS2005)
BeitragVerfasst: Di 28.11.06 15:28 
Es gibt keine compile time fixed size Arrays in .Net.
Es gibt sogenannte "bound arrays", aber die sind a) langsam und b) was ganz anderes als ein normaler szArray.
Wenn du in Delphi.Net einen Array wie beschrieben deklariert hast, dürftest du ziemliche Probleme in einer richtigen .Net-Sprache kriegen.

Ein byte array, der nach CLS benutzt werden kann sollte einfach so aussehen:
ausblenden C#-Quelltext
1:
2:
void SomeMethod(Byte[] someBytes)
{}
shil
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 143

Windows Xp
C#
BeitragVerfasst: Do 30.11.06 15:25 
bin mir nicht ganz sicher ob du das gemient hast:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
public void Main(sting[] args)
{
string[] arrayName = new string[10]

arrayName[1] = "test";

Console.WriteLine(arrayName[1];
}


mit string[] arrayName = new string[10] erstellst du dir dein array und legst gleizeitig fest wieviele elemente in deinem array sind.

p.s: den typ des arrays habe ich jetzt mal als string gesetzt, kannst aber auch jeden anderen nehmen.
Baumunk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 50

WinXP
Delphi 2005
BeitragVerfasst: Do 30.11.06 15:40 
Hallo shil,

Da hast fast in schwarze getroffen.
Ich brauche jedoch, array der nicht aus 10 string besteht, sondert
das array der 10 elemenden besteht der auch array aus 3 int ist.

Also quasi zwei demsionales array [10][3].

Das ist alles.

Zur zeit habe das mit dem neuen Class noz gelöst der als default Property array hat.

Danke Ernest
shil
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 143

Windows Xp
C#
BeitragVerfasst: Do 30.11.06 15:47 
also meinst du
ausblenden C#-Quelltext
1:
int[][] arrayName = new int[10][3]					


das array hat 10 dimensionen a 3 "arrayplätze"
Baumunk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 50

WinXP
Delphi 2005
BeitragVerfasst: Do 30.11.06 16:02 
Hallo shil,

Im prinzip ja, bloß wenn ich es so wie du vorschlägst schreibe:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
Int32 [][] b2 = new Int32 [mx + 1][3];

// oder dein variant

int[][] arrayName = new int[10][3];


markiert Compiler das zahl 3 und gib das als Fehler "Ungültige rangbezeichner: Erwartet wird "," oder "]".

Wie soll das denn deklarieren?

Danke Ernest
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Do 30.11.06 16:08 
In der Doku, die mit dem Visual Studio (oder dem SDK?) ausgeliefert wird, gibt es auch den C# Programming Guide. Ein Blick da rein lohnt sich. Unter folgender Hilfe-Seite ( ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_csref/html/bb79bdde-e570-4c30-adb0-1dd5759ae041.htm ) findet man das hier:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
class TestArraysClass
{
    static void Main()
    {
        // Declare a single-dimensional array 
        int[] array1 = new int[5];

        // Declare and set array element values
        int[] array2 = new int[] { 13579 };

        // Alternative syntax
        int[] array3 = { 123456 };

        // Declare a two dimensional array
        int[,] multiDimensionalArray1 = new int[23];

        // Declare and set array element values
        int[,] multiDimensionalArray2 = { { 123 }, { 456 } };

        // Declare a jagged array
        int[][] jaggedArray = new int[6][];

        // Set the values of the first array in the jagged array structure
        jaggedArray[0] = new int[4] { 1234 };
    }
}


Grüße
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Baumunk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 50

WinXP
Delphi 2005
BeitragVerfasst: Do 30.11.06 16:18 
Ja, Danke Christian