xsharp.eu • X# equivalent of C# string cTest (One line syntax)
Page 1 of 1

X# equivalent of C# string cTest (One line syntax)

Posted: Tue May 29, 2018 6:34 pm
by ic2
Wolfgang pointed me to a feature he called One line syntax, if I understood well, this is the equivalent of C#'s:

string cTest ="x"

directly within the code.
That seemed like a good idea to solve warnings XS103 e.g. in error handlers TRY/CATCH giving:
Warning CS0168 The variable 'e' is declared but never used

But I can't find this back in the help. I just defined a variable without declaring, this of course gives XS103 and the help says very promising " The following example resolves the error." except the sample box is empty...

How do I write string cTest ="x" in X#?

Dick

X# equivalent of C# string cTest (One line syntax)

Posted: Tue May 29, 2018 6:45 pm
by SHirsch
Hi Dick,

var cTest := "x"

or

LOCAL cTest := "x" AS STRING

Stefan

X# equivalent of C# string cTest (One line syntax)

Posted: Tue May 29, 2018 7:06 pm
by ic2
Hello Stefan,

That's quick!

Ok, it's that simple....

And indeed it works and is indeed very convenient.

I will paste a dozen of local cMessage:=e:Message as string or so which saves an equal number of warnings.

Dick

X# equivalent of C# string cTest (One line syntax)

Posted: Tue May 29, 2018 9:17 pm
by Chris
Hi Dick,

In order to solve the problem with this exact issue, the compiler in the latest build supports a new syntax for CATCH:

CATCH AS Exception

(so no variable name). You can use this one to get rid of the warning, in places when you do not really need to use the Excaption variable (I know, there are plenty such situations).

hth,
Chris

X# equivalent of C# string cTest (One line syntax)

Posted: Wed May 30, 2018 6:28 am
by ic2
Hello Chris,
CATCH AS Exception

That's even better, in quite some situations!

Dick