Path: ...!weretis.net!feeder9.news.weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=C3=B8j?= Newsgroups: comp.os.vms Subject: Re: Simple Pascal question Date: Tue, 6 Aug 2024 19:57:50 -0400 Organization: A noiseless patient Spider Lines: 65 Message-ID: References: <20240805153449.00000ff6@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Wed, 07 Aug 2024 01:57:49 +0200 (CEST) Injection-Info: dont-email.me; posting-host="e632d317eb5655b40c9780b24efa7403"; logging-data="2047107"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18SjT/CH0pyP62GfFDFkGagDXqrVGQk//w=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:vt9wiLlQm5cZADw41i8x8QTwuDY= Content-Language: en-US In-Reply-To: <20240805153449.00000ff6@yahoo.com> Bytes: 3204 On 8/5/2024 8:34 AM, Michael S wrote: > On Sun, 4 Aug 2024 21:00:35 -0400 > Arne Vajhøj wrote: >> On 8/4/2024 8:09 PM, Dan Cross wrote: >>> In article , >>> Arne Vajhøj wrote: >>>> Like: >>>> >>>> public class FlexArray { >>>> private static void dump(int[] a) { >>>> for(int v : a) { >>>> System.out.printf(" %d", v); >>>> } >>>> System.out.println(); >>>> } >>>> public static void main(String[] args) throws Exception { >>>> int[] a1 = { 1 }; >>>> int[] a2 = { 1, 2 }; >>>> int[] a3 = { 1, 2, 3 }; >>>> dump(a1); >>>> dump(a2); >>>> dump(a3); >>>> } >>>> } >>> >>> Java arrays are more like the aforementioned slices. >> >> I don't think so. >> >> Java does not have anything like slices. >> >> C# does. >> >> C# Span is similar to slices. But C# Span and C# array are far from >> the same. > > Pay attention that despite being designed (or at least brought to > public) in this century, C# originally lacked slices. > They were added relatively recently, in v. 8.0, and referred in c# docs > as "Indices and ranges". I thought it was C# 7.2. It is important to note that C# Span and Range are a little bit different than similar syntax in some of the newer native languages supporting slice. int[] a = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }; Span s1 = a[1..3]; does not create a span/slice/view of the second and third element of a - it allocates a new array of length 2, copy the second and third element of a to it and create a span/slice/view of the new array. Span s2 = ((Span)a).Slice(1, 2); Span s3 = (new Span(a)).Slice(1, 2); Span s4 = new Span(a, 1, 2); all create a span/slice/view of the second and third element of a. Arne