Share vb.net 1 based array

#vb.net #Array #1 dựa trên-array #Array-indexing #Zero dựa trên-ARRAY

** Các mảng dựa trên 1 trong vb.net **

Trong VB.NET, các mảng không dựa trên 0 theo mặc định.Điều này có nghĩa là phần tử đầu tiên trong một mảng là tại INDEX 0, phần tử thứ hai là tại INDEX 1, v.v.Tuy nhiên, cũng có thể tạo các mảng dựa trên 1 trong vb.net.Để làm điều này, bạn chỉ cần chỉ định từ khóa `mảng` với tham số` 1`.Ví dụ: mã sau đây tạo ra một mảng số nguyên dựa trên 1:

`` `VBNet
Dim myArray as Integer () = New Integer (1 đến 10) {}
`` `

Mảng `myArray` hiện chứa 10 phần tử, bắt đầu tại INDEX 1. Bạn có thể truy cập các phần tử của mảng bằng toán tử` [] `.Ví dụ: mã sau in giá trị của phần tử đầu tiên trong mảng:

`` `VBNet
Console.WriteLine (MyArray (1))
`` `

Đầu ra:

`` `
1
`` `

Các mảng dựa trên 1 thường được sử dụng trong các ứng dụng toán học và khoa học.Ví dụ, một mảng dựa trên 1 có thể được sử dụng để lưu trữ các giá trị của hàm tại các điểm khác nhau trên trục x.

###### Người giới thiệu

* [Các mảng dựa trên 1 trong vb.net] (Array Class (System) (int))
=======================================
#vb.net #Array #1-based-array #Array-indexing #Zero-based-array ##1-based-array in vb.net

**1-based arrays in VB.NET**

In VB.NET, arrays are zero-based by default. This means that the first element in an array is at index 0, the second element is at index 1, and so on. However, it is also possible to create 1-based arrays in VB.NET. To do this, you simply need to specify the `Array` keyword with the `1` parameter. For example, the following code creates a 1-based array of integers:

```vbnet
Dim myArray As Integer() = New Integer(1 To 10) {}
```

The `myArray` array now contains 10 elements, starting at index 1. You can access the elements of the array using the `[]` operator. For example, the following code prints the value of the first element in the array:

```vbnet
Console.WriteLine(myArray(1))
```

Output:

```
1
```

1-based arrays are often used in mathematical and scientific applications. For example, a 1-based array could be used to store the values of a function at different points on the x-axis.

###### References

* [1-based arrays in VB.NET](https://docs.microsoft.com/en-us/dotnet/api/system.array?view=net-6.0#ctor(int))
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top