USING syntax ? - help please ...

This forum is meant for questions and discussions about the X# language and tools
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

USING syntax ? - help please ...

Post by Phil Hepburn »

Hi Robert and all,

Thanks for the multiple USING syntax.

I have applied the syntax to part of a sample I am currently doing for ClickStartXSharp, involving Await methods in 'Stream' classes.

The code is below - it reads one file and creates two more with the read contents :-

Code: Select all

public async method MyStreamReaderWriterTest(cFilePath as string, cNuFile1 as string, cNuFile2 as string) as void
        if File.Exists(cFilePath)
            begin using local sw1 := StreamWriter{cNuFile1}, ;  
                              sw2 := StreamWriter{cNuFile2} as StreamWriter 

                begin using local sr := StreamReader{cFilePath} as StreamReader
                    local cDetails as string
                    try
                        local cResult := "" as string
                        cResult := await sr:ReadToEndAsync()
                        MessageBox.Show(cResult,"File contents :")
                        await sw1:WriteAsync(cResult)
                        await sw2:WriteAsync(cResult)
                    catch oEX as SystemException
                        MessageBox.Show(oEX:Message,"my Error buffering :")
                    end try
                end using
            end using
        else
            MessageBox.Show("No such file found on disc ....","my Error file reading :")
        endif
    return
My problem is how to write code so that all three are in one USING statement.

Is this possible ?

Personally, I think I could make it more readable to help keep Wolfgang happy, but is it allowed, and if so what is the syntax ?

Here is the result :-
MultipleUsings_01.png
MultipleUsings_01.png (25.83 KiB) Viewed 160 times
Regards,
Phil.
Post Reply