Deutsch   English   Français   Italiano  
<v8ud9t$1uf43$2@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

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?= <arne@vajhoej.dk>
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: <v8ud9t$1uf43$2@dont-email.me>
References: <v8goeh$2b5op$1@dont-email.me> <v8lpj0$ems$1@panix2.panix.com>
 <v8nrp9$3tp$1@reader1.panix.com> <v8o4h8$2ut3$1@dont-email.me>
 <v8p58c$gmo$1@reader1.panix.com> <v8p87j$9ptm$3@dont-email.me>
 <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 <arne@vajhoej.dk> wrote:
>> On 8/4/2024 8:09 PM, Dan Cross wrote:
>>> In article <v8o4h8$2ut3$1@dont-email.me>,
>>> Arne Vajhøj  <arne@vajhoej.dk> 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<int> 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<int> s2 = ((Span<int>)a).Slice(1, 2);
Span<int> s3 = (new Span<int>(a)).Slice(1, 2);
Span<int> s4 = new Span<int>(a, 1, 2);

all create a span/slice/view of the second and third
element of a.

Arne