Byte array

sanojsanoj Member Posts: 19
edited 2013-12-17 in NAV Three Tier

I am using the new Dotnet datatype and I'm trying to rewrite the following c# code in c/al, but can't figure out how...
int buffLength = 2048;
byte[] buff = new byte[buffLength];

How do I write this in c/al?

Br, Jonas


  • Options
    deV.chdeV.ch Member Posts: 543
    As from what i know, you can't use dotnet datatypes directly, so you can't create a byte array.


    But since System.Byte is mapped to the C/AL Datatype Char you could make a char array of the size you need and use that one? (Not tested)

  • Options
    BeliasBelias Member Posts: 2,998
    there's also a WONDERFUL, OUTSTANDING session by vjekoslav babic, done at the navtechdays that explains a lot of things (array and CAL/.NET datatype mapping included).
    you can download it here
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • Options
    sanojsanoj Member Posts: 19

    Thanks for your replies. After looking at the video ( great by the way ) I figured out how to do it. I used the wrapper.

    Sorry that Microsoft hasn't provided us with these wrappers in NAV... In my opinion, one great thing about the Dotnet interop is that you don't have to distribute a lot of dll:s. But to handle this, you have to distribute the wrapper... :(

    Br, Jonas
  • Options
    u382514u382514 Member Posts: 12
    I know this is quite old but this is how I did it...

    Two Variables:
    Name DataType Subtype
    NETArray DotNet System.Array.'mscorlib, Version=, Culture=neutral,...
    NETType DotNet System.Type.'mscorlib, Version=, Culture=neutral,...

    In C/AL:

    NETType := NETType.GetType('System.Byte',FALSE);
    NETArray := NETArray.CreateInstance(NETType, NETConvert.FromBase64String(BigString).Length);

    NOTE: NETConvert was another DotNet variable for Encoding.

    NETArray is now your byte array and you can write to it. The only downfall I've found is the fact that you have to create an instance knowing the length up front. So for me I had to 'getbytes' twice...but at least it keeps everything in C/AL.
Sign In or Register to comment.