thaburner
asked on
Read/Write Array in Array
I'm new to C# and trying to figure out the best/easiest way to handle this. What I need to accomplish is having (ID, Host, EmployeeID, Permission, Value) as an array inside another array (Employee). The code I included is from PHP of how I handled this. If I can get an example of how to read/write this or get pointed in the right direction that would be very helpful.
foreach ($_SESSION['Employee'] as &$value) {;
$ReturnArray[] = array("ID" => $value["ID"],
"Host" => $value["Host"],
"EmployeeID" => $value["EmployeeID"],
"Permission" => $value["Permission"],
"Value" => $value["Value"]);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I can add that there is a .ToArray()-method on the List. So you can create back to arrays whenever you like with this.Employees.ToArray() or this.Amployees.ToArray<Emp loyeeInfo> ()
TheHollow is spot on. Using a generic is preferrable to using an array. The List<> is one of these generics that is available by using the System.Collection.Generic namespace.
http://www.dotnetperls.com/list
http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx
-saige-
http://www.dotnetperls.com/list
http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx
-saige-
ASKER
That worked perfect!!! Thanks.
Here is, in its simplest form, the way to create your class, usually in its own file. You will have to adjust the types to the type of values you use. Properties would be a better programming practice, but would take more work to code, unless you were in VB or unless they have a shortcut I do not know about in C#.
Open in new window
In the application, you declare and use your array this way:Open in new window
Your second array becomes the fields in the first array. It is a lot easier to understand the code with Employees[2].Host thant it woud be with Employees[2][4].