Autor |
Beitrag |
Baumunk
Beiträge: 50
WinXP
Delphi 2005
|
Verfasst: Di 28.11.06 14:39
Hallo,
Mal wieder anfeänger frage.
Wie deklarie ich folgendes Typ, der in Delphi so zu delkarieren ist:
Delphi-Quelltext 1: 2: 3: 4: 5:
| type RGBArray = array[0..2] of Byte;
var B: array of RGBArray; |
in c# ?
voraus danke
|
|
Robert_G
Beiträge: 416
Delphi32 (D2005 PE); Chrome/C# (VS2003 E/A, VS2005)
|
Verfasst: 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:
C#-Quelltext 1: 2:
| void SomeMethod(Byte[] someBytes) {} |
|
|
shil
Beiträge: 143
Windows Xp
C#
|
Verfasst: Do 30.11.06 15:25
bin mir nicht ganz sicher ob du das gemient hast:
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
Beiträge: 50
WinXP
Delphi 2005
|
Verfasst: 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
Beiträge: 143
Windows Xp
C#
|
Verfasst: Do 30.11.06 15:47
also meinst du
C#-Quelltext 1:
| int[][] arrayName = new int[10][3] |
das array hat 10 dimensionen a 3 "arrayplätze"
|
|
Baumunk
Beiträge: 50
WinXP
Delphi 2005
|
Verfasst: Do 30.11.06 16:02
Hallo shil,
Im prinzip ja, bloß wenn ich es so wie du vorschlägst schreibe:
C#-Quelltext 1: 2: 3: 4: 5:
| Int32 [][] b2 = new Int32 [mx + 1][3];
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.
Beiträge: 20451
Erhaltene Danke: 2264
Win 10
C# (VS 2019)
|
Verfasst: 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:
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() { int[] array1 = new int[5];
int[] array2 = new int[] { 1, 3, 5, 7, 9 };
int[] array3 = { 1, 2, 3, 4, 5, 6 };
int[,] multiDimensionalArray1 = new int[2, 3];
int[,] multiDimensionalArray2 = { { 1, 2, 3 }, { 4, 5, 6 } };
int[][] jaggedArray = new int[6][];
jaggedArray[0] = new int[4] { 1, 2, 3, 4 }; } } |
Grüße
Christian
_________________ Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
|
|
Baumunk
Beiträge: 50
WinXP
Delphi 2005
|
Verfasst: Do 30.11.06 16:18
|
|