CodeDocu.com

C #: Add Item to Array or List
 
Task:
How to add an item to an array in a C # application?
 
Solution:
Instead of string [] array_example you normally use List <string> arrList in c #
A list corresponds to a one-dimensional array and can be extended with .add at runtime
 
Create a list
Corresponding to a one-dimensional array

 
private List<string> meine_Liste = new List<string>();
 

 
 
Queries for entries
With List.Contains (entry) one can check, if the list contains the entry

arrFolder_Dates.Contains(sDate)==false

 
 
Add new elements
You can easily paste with .Add (Sting entry)

arrFolder_Dates.Add(sDate);

 
 
C # Code example for defining a list, querying for inserting and appending items

 
private List<string> arrFolder_Dates = new List<string>();
 
private void fxRead_Folder_Main(string sFolder_Path)
{
//----------------< fxRead_Folder() >----------------
{
//----< Selected Folder >----

//--------< Folder >--------
DirectoryInfo folder = new DirectoryInfo(sFolder_Path);
if (folder.Exists)
{
//------< @Loop: Files >------
foreach (FileInfo fileInfo in folder.GetFiles())
{
//----< File >----
if (".jpg|.mp4|.mov|.jpeg|.mpeg|.png".Contains(fileInfo.Extension.ToLower()))
{
//----< IsPhoto >----
String sDate = fileInfo.LastWriteTime.ToString("yyyy-MM-dd");
Debug.WriteLine("#Debug: File: " + fileInfo.Name + " Date:" + sDate);
 
//< Check String Array >
if (arrFolder_Dates.Contains(sDate)==false)
{
//--< not found >--
//< add UserControl >
add_UserControl(sDate);
//</ add UserControl >
 
//< add item in Array-List >
arrFolder_Dates.Add(sDate);
//</ add item in Array-List >

//--</ not found >--
}
//</ Check String Array >
//----</ IsPhoto >----
}
//----</ File >----
}
//------</ @Loop: Files >------
}
//--------</ Folder >--------
//----</ Selected Folder >----
}
//----------------</ fxRead_Folder() >----------------
}

 
 
Array Lists View under Visual Studio
C#: Add Item to Array or List

Software Entwicklung Stuttgart NĂ¼rtingen
Suche Projekte C#, WPF, Windows App,ASP.Net, vb.Net, WinForms, SQL Server, Access, Excel