You are returning a pointer to a stack memory location. That memory region is no longer valid once the function returns.

Also, instead of actually returning a pointer to the array, you are returning the first element in the array. The following code will return 1, not a pointer the array.

Use with AIint array[] {1, 2, 3, 4};
return *array

You probably only need to make minimal changes your code to get it to work.

Use with AIvoid** array = (void **) malloc(sizeof(void *) * array_size); 
...
return array;

Just make sure that you release the memory that memory used for array when you are finished with it.

Use with AIvoid **array = list_to_array(list);
// Use array
...
// Finished with array
free(array);
Answer from torak on Stack Overflow
Discussions

How do I convert a Python list into a C array by using ctypes? - Stack Overflow
How can I call the c_function with a contiguous list of elements in x? I tried to cast x to a c_void_p, but that didn't work. ... The C code clearly wants the address of an array. More on stackoverflow.com
๐ŸŒ stackoverflow.com
c# - Conversion from List<T> to array T[] - Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives ... Save this question. Show activity on this post. Is there a short way of converting a strongly typed List to an Array of the same type, e.g.: List to MyClass[]? More on stackoverflow.com
๐ŸŒ stackoverflow.com
c# - How to convert List<T> to Array? - Stack Overflow
I have a few other classes that have a huge number of elements. I've tried the below code, but it's throwing out of bound error. I need to automatically loop through elements in myclass and assign it to array and so on. Is there any alternative/one-liner statement for this to convert the entire list ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
March 8, 2022
How can I convert my list<string> to a string[ ] array?
using System.Linq; yoklama.ToArray() More on reddit.com
๐ŸŒ r/learncsharp
15
0
October 23, 2024
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-convert-a-c-sharp-list-to-an-array
How to convert a C# list to an Array
The List<T> class in the System.Collections.Generic namespace provides the ToArray() method, which can be used to convert a C# List to an Array.
๐ŸŒ
C# Corner
c-sharpcorner.com โ€บ UploadFile โ€บ c25b6d โ€บ conversion-from-list-to-array-and-vice-versa
How to convert C# List to an array?
September 8, 2023 - namespace ConsoleApplication8 { class Program { static void Main(string[] args) { //creation of list<> List<int> number = new List<int>(); //add the elements in the list number.Add(10); number.Add(20); number.Add(15); number.Add(25); number.Add(30); number.Add(35); number.Add(40); number.Add(45); //creation of an array int[] a = number.ToArray(); //display the array element Console.WriteLine("the array elements are:"); foreach (int i in a) { Console.WriteLine(i); } } } } ... In this example, we see how to convert an array of any number of elements to a List that has the same type of elements.
๐ŸŒ
arrayThis
arraythis.com
Online array converter; convert your text list to array | arrayThis
In the need to optimize your list (remove duplicates, empty lines, sort, prefix and suffix, etc.) use KitTxt before.
๐ŸŒ
Dot Net Perls
dotnetperls.com โ€บ convert-list-array
C# - Convert List to Array - Dot Net Perls
It is possible to convert arrays to Lists (and lists to arrays) with this code. We cannot just assign one to the other.
๐ŸŒ
Makolyte
makolyte.com โ€บ csharp-convert-a-list-to-an-array
C# - Convert list to array | makolyte
January 25, 2025 - The simplest way to convert a list to an array is to use the List.ToArray() method: This outputs the following: Internally, the List class stores elements inโ€ฆ
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c# โ€บ c-sharp-how-to-convert-an-arraylist-to-array
C# | How to convert an ArrayList to Array - GeeksforGeeks
July 11, 2025 - 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.
Find elsewhere
๐ŸŒ
Techie Delight
techiedelight.com โ€บ home โ€บ c++ โ€บ convert a list to an array in c++
Convert a list to an array in C++ | Techie Delight
July 7, 2026 - This post will discuss how to convert a list to an array in C++... A simple solution is to use a range-based for-loop to traverse the list and, one by one, add each element at the next available index in the array.
๐ŸŒ
FoxLearn
foxlearn.com โ€บ home โ€บ c# โ€บ how to convert list to array in c#
How to Convert list to array in C#
March 5, 2025 - The easiest way to convert a list to an array is by using the List.ToArray() method.
๐ŸŒ
YouTube
youtube.com โ€บ watch
C# - Convert list to array - YouTube
The video shows the code you can use to convert a list to an array.C# - How to convert a list to array
Published: September 28, 2015
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-do-you-convert-a-list-collection-into-an-array-in-chash
How to copy a List collection to an array?
June 22, 2020 - The most common approaches are the CopyTo() method, the ToArray() method, or creating an array with the List constructor.
๐ŸŒ
Techie Delight
techiedelight.com โ€บ home โ€บ java โ€บ convert list to array in c#
Convert List to Array in C# | Techie Delight
July 7, 2026 - This post will discuss how to convert a list to an array in C#... The ToArray() method returns an array containing copies of all the list elements.
๐ŸŒ
Adobe
helpx.adobe.com โ€บ home โ€บ adobe coldfusion user guides โ€บ listtoarray
ListToArray
December 4, 2025 - <cfset list = "red,orange,&yellow,green,&blue,violet"> <cfset arr = listToArray (list, ",&",false,true)> ... <cfscript> myList="ten;twenty;thirty;fort;fifty;sixty;;seventy;;;eighty"; // list contains empty elements // convert myList to myArray myArray=listToArray(myList,";",false,true); // ...
๐ŸŒ
Reddit
reddit.com โ€บ r/learncsharp โ€บ how can i convert my list to a string[ ] array?
r/learncsharp on Reddit: How can I convert my list<string> to a string[ ] array?
October 23, 2024 -

I am trying to write a simple code that will print out some names alphabetically but I wanna do it using a list.

I know that Array.Sort(); exists but I couldnt find a way to convert my list to an array.

using System; using System.Collections.Generic;

namespace siniflistesi { class Program { static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.DarkCyan; Console.WriteLine("12-A sinif listesini gormek icin herhangi bir tusa basiniz."); Console.ReadKey(); Console.Clear();

List<string> yoklama = new List<string>(); string[] thearray = new string[yoklama.Count]; yoklama = Convert."i couldnt find an array option here" (thearray); Array.Sort(yoklama);

yoklama.Add ("Nehir"); yoklama.Add ("Zumra"); yoklama.Add ("Elif");

for (int i = 0; i < yoklama.Count; i++) { Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine(yoklama[i]); } Console.ReadKey(); } } }