---
title: "Adding data to an array of struct"  
description: "Adding data to an array of struct"  
author: "Anonymous User"  
published: 2013-09-23  
updated: 2013-09-23  
canonical: https://www.mindstick.com/forum/1483/adding-data-to-an-array-of-struct  
category: "wpf"  
tags: ["wpf"]  
reading_time: 2 minutes  

---

# Adding data to an array of struct

I'm trying to add/[remove data](https://www.mindstick.com/forum/159778/what-is-the-delete-statement-in-sql-and-how-is-it-used-to-remove-data-from-a-table) from an array of a defined struct.

struct [process](https://yourviews.mindstick.com/story/1525/7-important-factors-that-may-affect-the-learning-process)

{

public int Proc_Id;

public int Proc_BurstTime;

public int Proc_Priority;

public override [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) [ToString](https://www.mindstick.com/interview/2259/what-is-the-difference-between-tostring-convert-tostring)()

{

return "ID: " + Proc_Id.ToString() + " Time: " + Proc_BurstTime.ToString() + " Prior: " + Proc_Priority.ToString();

}

};

[readonly](https://www.mindstick.com/forum/1419/how-can-i-make-the-wpf-datagrid-cells-readonly) process[] ProcessList = new process[]

{

new process{ Proc_Id = 1, Proc_BurstTime = 3000, Proc_Priority = 1},

new process{ Proc_Id = 2, Proc_BurstTime = 5000, Proc_Priority = 2},

new process{ Proc_Id = 3, Proc_BurstTime = 1000, Proc_Priority = 3},

new process{ Proc_Id = 4, Proc_BurstTime = 10000, Proc_Priority = 4}

};

Basically, what I'm exactly trying to do is [populate](https://www.mindstick.com/blog/60/populate-records-in-second-listbox-according-to-the-selection-in-first-list-box) this array of structs into a [ListBox control](https://www.mindstick.com/articles/395/listbox-control-in-c-sharp-dot-net). I have been able to initially populate it by using [DataSource](https://www.mindstick.com/blog/447/listing-the-databases-connected-to-the-datasource), I've also been able to modify the contents and "re-datasource" it to [update](https://www.mindstick.com/forum/156353/what-is-hummingbird-update) the ListBox. However, I cannot ADD or REMOVE processes. Does anyone know what I can do?

## Replies

### Reply by Sumit Kesarwani

Hi Tanuj,\

You'll need to use a collection.

```
A List<T> would do just fine.var processes = new List<process>();processes.Add(new process{    Proc_Id = 1,     Proc_BurstTime =
3000,     Proc_Priority = 1});Modifying your code a bit would result in this below.List<process> ProcessList = new List<process>(){    new process
{Proc_Id = 1, Proc_BurstTime = 3000, Proc_Priority = 1},    new process
{Proc_Id = 2, Proc_BurstTime = 5000, Proc_Priority = 2},    new process
{Proc_Id = 3, Proc_BurstTime = 1000, Proc_Priority = 3},    new process {Proc_Id
= 4, Proc_BurstTime = 10000, Proc_Priority = 4}};
```


---

Original Source: https://www.mindstick.com/forum/1483/adding-data-to-an-array-of-struct

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
