C# : What should I use: Array or ArrayList or List of list?

i'm learning C# and i need some advise.

I'm trying to create users (Active Directory) from an XML file. Those users are students and teachers. For each user i need his name, surname, birthdate to generate his login, password.

  • A student can be only member of one groupe (his class).
  • A teacher can have one or more group (classes where he teaches).

All information i need are in the XML.

In powershell, it works like this :

  • Students : tab[name,surname,birthdate,login,group] (and works also in c#)
  • Teachers : tab[name,surname,birthdate,login,tab[groups]]

How can i do this in C# ? I try with an Array in 3D but it his ugly and not very performant with hundreds of users ... Is there a better way to do this with lists ? ArrayList ?

Sorry for ma bad english ...

Thanks for your help (and pieces of code ^^) !

Example of the XML for the teachers :

<DATA>
-<PERSONS>
--<PERSON ID="6022">
---<NAME>DOE</NAME>
---<SURNAME>John</SURNAME>
---<BIRHDATE>1952-06-29</DATE_NAISSANCE>
--</PERSON>
--...
-</PERSONS>
-<CLASSES>
--<CLASS CODE="3A">
---<TEACHERS>
----<TEACHER ID="6022">
-----<SUBJECT>Maths</SUBJECT>
----</TEACHER>
---</TEACHERS>
--</CLASS>
--<CLASS CODE="5D">
---<TEACHERS>
----<TEACHER ID="6022">
-----<SUBJECT>Maths</SUBJECT>
----</TEACHER>
---</TEACHERS>
--</CLASS>
...
-</CLASSES>
</DATA>

Answers


You might want to take a look at XDocument.

You can create one by calling XDocument.Parse("<myDoc></myDoc>")

Example:

var xml = @"<DATA>
<PERSONS>
<PERSON ID=""6022"">
<NAME>DOE</NAME>
<SURNAME>John</SURNAME>
<BIRHDATE>19520629</BIRHDATE>
</PERSON>
</PERSONS>
<CLASSES>
<CLASS CODE=""3A"">
<TEACHERS>
<TEACHER ID=""6022"">
<SUBJECT>Maths</SUBJECT>
</TEACHER>
</TEACHERS>
</CLASS>
<CLASS CODE=""5D"">
<TEACHERS>
<TEACHER ID=""6022"">
<SUBJECT>Maths</SUBJECT>
</TEACHER>
</TEACHERS>
</CLASS>
</CLASSES>
</DATA>";

var doc = XDocument.Parse(xml);

var peopleElements = doc
    .Elements("DATA")
    .Elements("PERSONS")
    .Elements("PERSON");
var q = from person in peopleElements
select new {
    Name = person.Element("NAME").Value,
    BirthDate = person.Element("BIRHDATE").Value
};

var peopleList = q.ToList();

Need Your Help

Check Database Frequently in android

android database android-service android-calendar

I need to create an android app which save events and reminders in a database. When the correct time comes it should show a notification. For that case I need to create a service to look for events...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.