C list to array


Копирует элементы списка List в новый массив. Copies the elements of the List to a new array.

Возвращаемое значение

Массив, содержащий копии элементов списка List . An array containing copies of the elements of the List .


В следующем примере демонстрируется метод ToArray и другие методы класса List , действующие для диапазонов. The following example demonstrates the ToArray method and other methods of the List class that act on ranges. В конце примера метод GetRange используется для получения трех элементов из списка, начиная с позиции индекса 2. At the end of the example, the GetRange method is used to get three items from the list, beginning with index location 2. Метод ToArray вызывается для результирующего List , создавая массив из трех элементов. The ToArray method is called on the resulting List , creating an array of three elements. Отображаются элементы массива. The elements of the array are displayed.


Элементы копируются с помощью Array.Copy, которая является операцией O (n), где n — Count. The elements are copied using Array.Copy, which is an O(n) operation, where n is Count.

Этот метод является операцией O (n), где n — Count. This method is an O(n) operation, where n is Count.

In C#, an array is a group of like-typed variables that are referred to by a common name. And each data item is called an element of the array. The data types of the elements may be any valid data type like char, int, float etc. and the elements are stored in a contiguous location.

Читайте также:  Как заполнять данные карты на алиэкспресс

ArrayList represents an ordered collection of an object that can be indexed individually. It is basically an alternative to an array. It allows dynamic memory allocation, adding, searching and sorting items in the list.

Below are the two methods for converting an ArrayList to an Array:

Method 1: Convert an ArrayList to Array of object



  • It copy the elements of the ArrayList to a new Object array.
  • It return an Object array containing copies of the elements of the ArrayList.

Example: In the below program, mylist is the ArrayList and we added 7 items to it which are the name of weekdays. Then we are creating an object array obj1 and using ToArray method with mylist we will assign the Arraylist elements to the object array. Finally, using foreach loop you can print the required converted array.

Please complete the security check to access www.techiedelight.com

Why do I have to complete a CAPTCHA?

Completing the CAPTCHA proves you are a human and gives you temporary access to the web property.

What can I do to prevent this in the future?

If you are on a personal connection, like at home, you can run an anti-virus scan on your device to make sure it is not infected with malware.

If you are at an office or shared network, you can ask the network administrator to run a scan across the network looking for misconfigured or infected devices.

Another way to prevent getting this page in the future is to use Privacy Pass. You may need to download version 2.0 now from the Chrome Web Store.

Читайте также:  Сввкиу рв им ленинского комсомола

Cloudflare Ray ID: 55441c003b734eb2 • Your IP : • Performance & security by Cloudflare