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

This forum is meant for questions and discussions about the X# language and tools
Post Reply
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

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

Post 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
User avatar
SHirsch
Posts: 286
Joined: Tue Jan 30, 2018 8:23 am
Location: Germany

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

Post by SHirsch »

Hi Dick,

var cTest := "x"

or

LOCAL cTest := "x" AS STRING

Stefan
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

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

Post 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
User avatar
Chris
Posts: 4904
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

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

Post 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
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

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

Post by ic2 »

Hello Chris,
CATCH AS Exception

That's even better, in quite some situations!

Dick
Post Reply