A few days ago I ran into a test when I was asked to answer the following question: although this seems to be the main one, I have some doubts and my own opinion.
Publishing Center publishes books. A writer can write many books, and a book has an author
There were four options, and among them, I omitted two options that were not close. Thus, two options remain:
One option with a list :
public class Publisher { public int PublisherId { get; set;} public string PublisherName { get; set;} public string Address { get; set;} public List<Author> Authors { get; set;} public List<Book> Books{ get; set;} } public class Author { public int AuthorId { get; set;} public string AuthorName { get; set;} public string AuthorAddress { get; set;} public List<Book> Books{ get; set;} } public class Book { public int BookId { get; set;} public string BookName { get; set;} public Author Author { get; set;} }
Another option with an array :
public class Publisher { public int PublisherId { get; set;} public string PublisherName { get; set;} public string Address { get; set;} public Author[] Authors { get; set;} public Book[] Books{ get; set;} } public class Author { public int AuthorId { get; set;} public string AuthorName { get; set;} public string AuthorAddress { get; set;} public Book[] Books{ get; set;} } public class Book { public int BookId { get; set;} public string BookName { get; set;} public Author Author { get; set;} }
At the same time, I looked at this link to understand the difference: Vs Array List
After that, firstly, I chose the first option (my answer was that) and believe, List has more functionality and will be a better choice. Another reason is that I use EF in projects and when working with table relationships specifically for One-to-Many , then the created classes have a List collection as follows:
public List<Book> Books{ get; set;}
Secondly, I thought: if arrays can be used for the same thing, but what I learned is that the data structure of the array is ideal for fixed data. I hope I'm on the right track.
Finally, I could not understand two things from the provided link :
1) As a counter - List<T> is one-dimensional; where - since you have rectangular (etc.) arrays such as int [,] or string [,] - but there are other ways to model such data (if you need) in the object model
My views. One-dimensional means List one-dimensional array or something related.
2) A little embarrassed I mean, in which case should we use the following with Array ? Although this explains, it needs further clarification:
it performs a lot of bit-shift, so byte [] is very important for encoding;
I use the local byte buffer [], which I fill before sending to the base stream (and vv); faster than BufferedStream etc .;
- it internally uses an array-based object model (Foo [], not List), since the size is fixed after creation and should be very fast.