الشرائح
الشرائح
للمصفوفة حجم ثابت. أما الشريحة، فهي عرض ذو حجم ديناميكي، ومرن لعناصر مصفوفة. عمليًا، الشرائح أكثر شيوعًا بكثير من المصفوفات.
النوع []T هو شريحة عناصرها من النوع T.
تُشكَّل الشريحة بتحديد فهرسين، حدّ أدنى و حدّ أعلى، تفصل بينهما نقطتان رأسيتان:
a[low : high]
يحدّد هذا نطاقًا نصف مفتوح يشمل العنصر الأول، لكنه يستثني العنصر الأخير.
ينشئ التعبير التالي شريحة تشمل
العناصر من 1 إلى 3 من a:
a[1:4]
النص الأصلي بالإنجليزية
Slices
An array has a fixed size. A slice, on the other hand, is a dynamically-sized, flexible view into the elements of an array. In practice, slices are much more common than arrays.
The type []T is a slice with elements of type T.
A slice is formed by specifying two indices, a low and high bound, separated by a colon:
a[low : high]
This selects a half-open range which includes the first element, but excludes the last one.
The following expression creates a slice which includes
elements 1 through 3 of a:
a[1:4]
هذا الدرس للقراءة فقط؛ جرّب المثال في الدرس التالي.