fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: 2D 'matrix' .NET arrays - HELP syntax !!!

2D 'matrix' .NET arrays - HELP syntax !!! 1 year 7 months ago #3088

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
Hi Robert, Chris, any guy who knows,

Please help me get the correct syntax for declaring and initializing a 2D 'rectangular' array of the .NET variety.

So far in my research on Arrays I have been doing okay - until I hit the wall just now trying to convert the attached C# code.



TIA,
Phil.

P.S. here is some syntax which I got to work for me :-

Attachments:

Please Log in or Create an account to join the conversation.

2D 'matrix' .NET arrays - HELP syntax !!! 1 year 7 months ago #3090

  Frank Maraite's Avatar Frank Maraite Offline Posts: 173
Hi Phil, Chris,

this works
LOCAL numbersOne  AS INT[]
	numbersOne := <INT>{1,2,3,4,5,6}
but this
LOCAL numbersTwo AS INT[,]
	numbersTwo := {{1,2},{3,4},{5,6}}
gives XS9008 Untyped arrays are not available in the selected dialect 'Core'
Here
numbersTwo := <INT>,<INT>{{1,2},{3,4},{5,6}}
XS9002: Parser: unexpected input 'numbersTwo'
The same with
numbersTwo := <<INT>,<INT>>{{1,2},{3,4},{5,6}}

Sorry, I'm not the guy who knows

Frank

Please Log in or Create an account to join the conversation.

2D 'matrix' .NET arrays - HELP syntax !!! 1 year 7 months ago #3093

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
Yep! - Frank,

Now you see how I was getting into a mess - I think I tried just about every sensible (and desperate) combination of syntaxes - I got a lot of .... selected dialect 'Core' error messages.

Its the 2D, 3D, .... XD which is giving me issues.

Hopefully Robert, Chris, Nikkos may be able to shed some light :unsure:

HELP still required !
Phil.
Wales, UK.

Please Log in or Create an account to join the conversation.

2D 'matrix' .NET arrays - HELP syntax !!! 1 year 7 months ago #3102

  Frank Maraite's Avatar Frank Maraite Offline Posts: 173
Hi Phil,

look what I found in old code:

LOCAL avals AS Double[][]
avals := <Double[]>{<Double>{1.0, 4.0, 7.0, 10.0}, <Double>{2.0, 5.0, 8.0, 11.0}, <Double>{3.0, 6.0, 9.0, 12.0}}

But realise: Double[][] is not the same as Double[,]. It is an one dimensional array of one dimensional arrays.

With that construction we can get a complete column of values by

local oneColumn as Double[]
oneColumn := avals[0] // One dimensional access to the first column.
oneColumn:Length is 4 now.

This lets us sort rows or rearrange arrays a little bit easier.
Frank

Please Log in or Create an account to join the conversation.

2D 'matrix' .NET arrays - HELP syntax !!! 1 year 7 months ago #3106

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
Hi Frank,

Yes, and thanks ;-0) for the tip and sharing.

This is called a 'jagged array' I believe, and as you can see in the image of my eNotes sections the one I want is a 'multi-dimensional array' :-



And I will do 'Mixed' arrays as well.

Your previous help with __ARRAYBASE__ has worked out very well this afternoon - THANKS!
Phil.
Attachments:

Please Log in or Create an account to join the conversation.

2D 'matrix' .NET arrays - HELP syntax !!! 1 year 7 months ago #3107

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
Hi Frank,

Following your syntax 'format' and others similar, the following seems the most likely to be correct I feel. But it does not work for me in X#.



I have a gut feeling that the compiler may not be 100% on the topic of multi-dimensional arrays.

We need to wait for Robert and his TEAM ;-)

Cheers,
Phil.
Attachments:

Please Log in or Create an account to join the conversation.

2D 'matrix' .NET arrays - HELP syntax !!! 1 year 7 months ago #3108

  Chris's Avatar Chris Offline Posts: 1164
Hi guys,

Sorry for the delay, I was also trying to find out if it's a bug or feature that this is not working currently :)
I think it's a mixup, the compiler confuses the VO-style ARRAY syntax with the .Net style array initialization here. I'll log this as a bug so it will be taken care off, for now you'll need to initialize the array elements the old-fashioned way (a[1,1] := 1 etc).

Chris
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

2D 'matrix' .NET arrays - HELP syntax !!! 1 year 7 months ago #3111

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
Thanks Chris,

I had a feeling something not quite right was up ! Thanks for getting back to us.

For now I will do as you say and get on with researching and writing the rest of my session material and eNotes for Cologne 2018.

If I find anything else 'odd' I will get back to you.

Best wishes,
Phil.
Wales, UK.

Please Log in or Create an account to join the conversation.

2D 'matrix' .NET arrays - HELP syntax !!! 1 year 7 months ago #3161

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
Hi Frank,

Thanks for the jagged array sample reminder.

I used it this afternoon to research and add detail to the sub-section in my ClickStart eNotes on Arrays in X# code syntax.

I attach a small sample image.



My brain now dead, and time for tea ;-0)

Cheers,
Phil.
Attachments:

Please Log in or Create an account to join the conversation.

  • Page:
  • 1