Autor Beitrag
Peter1000
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 60



BeitragVerfasst: Mo 27.10.14 12:09 
Hallo,

ich habe eine Datei mit 100.000 Integer-Werten. (Dateigroesse ist dann 400.000 Byte)
Nun ist es aber so, (afaik) dass mit FileStream nur Bytes eingelesen werden koennen.

Wie kann ich am schnellsten diese 100.000 Int-Werte in ein Integer-Array einlesen?

THX


Moderiert von user profile iconTh69: Topic aus C# - Die Sprache verschoben am Mo 27.10.2014 um 13:16
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mo 27.10.14 14:20 
Hallo,

benutze dafür den BinaryReader (ReadInt32).
Oder alternativ jeweils 4 Bytes lesen und diese dann per BitConverter.ToInt32 umwandeln.
C#
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 561
Erhaltene Danke: 65

Windows 10, Kubuntu, Android
Visual Studio 2017, C#, C++/CLI, C++/CX, C++, F#, R, Python
BeitragVerfasst: Mo 27.10.14 14:21 
Hallo,

am besten du liest immer 4 Bytes ein und jagst sie dann durch den BitConverter:
ausblenden C#-Quelltext
1:
2:
3:
4:
 
byte[] array = new byte[4];
fs.Read(array, deinIndex, 4);
int val = BitConverter.ToInt32(array,0);


// Nachtrag
Th69 war schneller...

_________________
Der längste Typ-Name im .NET-Framework ist: ListViewVirtualItemsSelectionRangeChangedEventHandler