Hi Horst,
This is why I hate the VAR command, because it hides the information about the names of the types used. OpenRead() is a STATIC (not instance) method of the ZipFile class (basically it's just like a common function), so you need to use the dot to use it, not a colon (you must use a colon when you are calling a method of an instance, ie in a local, but here, there's no local). This method returns an instance of the "ZipArchive" class.
Additionally, the "using" you see in the middle of the code, is a very different thing to the "using"s in the beginning of the file (yes, unfortunately c# uses "using" for so many different things, like it also does with the dot operator), it's a code construct to automatically restrict visibility of the local and call an object's Dispose() method at the end of the construct. Direct equivalent of the code in X# would be (removing the unnecessary stuff):
Code: Select all
USING System.IO.Compression
FUNCTION Start( ) AS VOID
LOCAL cZipFile := "ubs.zip" AS STRING
BEGIN USING LOCAL oArchive := ZipFile.OpenRead(WorkDir()+cZipFile) AS ZipArchive
FOREACH entry AS ZipArchiveEntry IN oArchive:Entries
Console.WriteLine(entry:Name)
NEXT
END USING
In order to make the code a bit easier to understand, it could be expanded to the almost identical:
Code: Select all
USING System.IO.Compression
FUNCTION Start( ) AS VOID
LOCAL cZipFile := "ubs.zip" AS STRING
LOCAL oArchive AS ZipArchive
oArchive := ZipFile.OpenRead(WorkDir()+cZipFile)
FOREACH entry AS ZipArchiveEntry IN oArchive:Entries
Console.WriteLine(entry:Name)
NEXT
oArchive:Dispose()