Options

DOTNET foreach

kenjeskenjes Member Posts: 76
Hi

I have this .NET code :
foreach (DataRow JournalDR in objJournal.GetAllNonSyncedJournalsAndNonProcessed().Rows)


Can I "convert" it to NAV 2016.. somehow :)

Thanks.

Best Answer

Answers

  • Options
    vaprogvaprog Member Posts: 1,118
    edited 2017-03-13
    You need to either use the Item property or something similar (see https://msdn.microsoft.com/en-us/library/hh165881(v=nav.90).aspx), or use an enumerator object.

    Below is an example where I search a Dictionary for a Value to get back the Key:
    VAR
      TableDict@1000000000 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Collections.Generic.Dictionary`2";
    PROCEDURE TableNameFromID@1000000007(TableNo@1000000000 : Integer) Name : Text;
    VAR
      Enum@1000000003 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Collections.Generic.Dictionary`2+Enumerator";
      KeyVal@1000000002 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Collections.Generic.KeyValuePair`2";
      FieldNoDict@1000000004 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Collections.Generic.Dictionary`2";
      No@1000000005 : Integer;
    BEGIN
      IF ISNULL(TableDict) THEN
        FillTableDict;
    
      Enum := TableDict.GetEnumerator;
      WHILE Enum.MoveNext DO BEGIN
        KeyVal := Enum.Current;
        No := KeyVal.Value;
        IF No = TableNo THEN
          EXIT(KeyVal.Key);
      END;
      EXIT(FORMAT(TableNo));
    END;
    
  • Options
    ara3nara3n Member Posts: 9,255
    NAV 2016 has FOREACH and you can use it for dotnet types.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    kenjeskenjes Member Posts: 76
    Hi ara3n

    Yes, i know
    but I can't figure out how to use it like :

    foreach (DataRow JournalDR in objJournal.GetAllNonSyncedJournalsAndNonProcessed().Rows)
  • Options
    kenjeskenjes Member Posts: 76
    Thanks ara3n
Sign In or Register to comment.