{"id":166,"date":"2009-11-13T19:05:15","date_gmt":"2009-11-13T18:05:15","guid":{"rendered":"http:\/\/www.gennard.net\/blog\/?p=166"},"modified":"2009-11-13T19:05:15","modified_gmt":"2009-11-13T18:05:15","slug":"arrays-and-the-net-base-cass-library","status":"publish","type":"post","link":"http:\/\/www.gennard.net\/blog\/2009\/11\/arrays-and-the-net-base-cass-library\/","title":{"rendered":"Arrays and the .Net Base Cass Library"},"content":{"rendered":"<p>Carrying on from the previous blog, the user of iterators in .Net and especially .Net on COBOL can be very useful.<\/p>\n<p>When CLR v2.0 was introduced a few new methods in System.IO.File for block reading\/writing files were introduced, these works on arrays aka &#8220;OCCURS ANY&#8221; fields.  Using these APIs instead of using traditional line sequentials is a breath of fresh air, especially if you just want to do some code something quickly without the need of records\/group items.<\/p>\n<p>So lets.. have a little play around, lets read a &#8220;MonthNames&#8221; from the CLR, write them to disk, read them back, reverse and sort it, while display them&#8230;<\/p>\n<p><code lang=\"cobol\" width=\"800\" lines=\"-1\" nowrap=\"0\"><br \/>\n       01 Months-Array type \"System.Array\".<\/p>\n<p>       01 Months string occurs 12.<br \/>\n       01 Month string.<\/p>\n<p>       *> Note: the MonthsNames has 13 elements and the last element is \"\"<br \/>\n       *> and I'm not interested it it so I'll drop it by doing a \"ConstrainedCopy\"<br \/>\n       *> with just elements I'm interested in.<br \/>\n       *> http:\/\/msdn.microsoft.com\/en-us\/library\/system.globalization.datetimeformatinfo.monthnames.aspx<br \/>\n       set Months-Array to type \"System.Globalization.DateTimeFormatInfo\"::\"CurrentInfo\"::\"MonthNames\"<br \/>\n       invoke type \"System.Array\"::\"ConstrainedCopy\"(Months-Array, 0, Months, 0, Months::\"Length\")<\/p>\n<p>       display Months::\"Length\"<br \/>\n       perform varying Month through Months<br \/>\n          display \"Normal  -> \" Month<br \/>\n       end-perform<\/p>\n<p>       *> Write the array to disk<br \/>\n       invoke type \"System.IO.File\"::\"WriteAllLines\"(\"MyMonths.txt\", Months)<\/p>\n<p>       set Months to null<\/p>\n<p>       *> Read it back<br \/>\n       set Months to type \"System.IO.File\"::\"ReadAllLines\"(\"MyMonths.txt\")<\/p>\n<p>       *> Reverse it<br \/>\n       invoke type \"System.Array\"::\"Reverse\"(Months as Type \"System.Array\")       <\/p>\n<p>       *> Display it<br \/>\n       perform varying Month through Months<br \/>\n          display \"Reverse -> \" Month<br \/>\n       end-perform<\/p>\n<p>       *> Sort it<br \/>\n       invoke type \"System.Array\"::\"Sort\"(Months as type \"System.Array\")<\/p>\n<p>       *> Display it<br \/>\n       perform varying Month through Months<br \/>\n          display \"Sorted  -> \" Month<br \/>\n       end-perform<\/p>\n<p><\/code><\/p>\n<p>Which when executed gives us: <\/p>\n<p><code lang=\"text\" width=\"800\" lines=\"-1\" nowrap=\"0\"><br \/>\n12<br \/>\nNormal  -> January<br \/>\nNormal  -> February<br \/>\nNormal  -> March<br \/>\nNormal  -> April<br \/>\nNormal  -> May<br \/>\nNormal  -> June<br \/>\nNormal  -> July<br \/>\nNormal  -> August<br \/>\nNormal  -> September<br \/>\nNormal  -> October<br \/>\nNormal  -> November<br \/>\nNormal  -> December<br \/>\nReverse -> December<br \/>\nReverse -> November<br \/>\nReverse -> October<br \/>\nReverse -> September<br \/>\nReverse -> August<br \/>\nReverse -> July<br \/>\nReverse -> June<br \/>\nReverse -> May<br \/>\nReverse -> April<br \/>\nReverse -> March<br \/>\nReverse -> February<br \/>\nReverse -> January<br \/>\nSorted  -> April<br \/>\nSorted  -> August<br \/>\nSorted  -> December<br \/>\nSorted  -> February<br \/>\nSorted  -> January<br \/>\nSorted  -> July<br \/>\nSorted  -> June<br \/>\nSorted  -> March<br \/>\nSorted  -> May<br \/>\nSorted  -> November<br \/>\nSorted  -> October<br \/>\nSorted  -> September<br \/>\n<\/code><\/p>\n<p>That was pretty easy&#8230; and the code looks okay too&#8230; can&#8217;t be bad&#8230;<\/p>\n<p>References : <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.globalization.datetimeformatinfo.monthnames.aspx\">System.Globalization.DatetimeFormat<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Carrying on from the previous blog, the user of iterators in .Net and especially .Net on COBOL can be very useful. When CLR v2.0 was introduced a few new methods in System.IO.File for block reading\/writing files were introduced, these works &hellip; <a href=\"http:\/\/www.gennard.net\/blog\/2009\/11\/arrays-and-the-net-base-cass-library\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,5,32],"tags":[],"_links":{"self":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/posts\/166"}],"collection":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/comments?post=166"}],"version-history":[{"count":0,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/posts\/166\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/media?parent=166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/categories?post=166"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/tags?post=166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}