Hello here my Question - I am an absolute beginner of C#
When I started a little programming there was no such thing as Objects
I have following situation. I have a Excel list similar like this
| Students | German | English | Maths | ... |
| Student 1 | 3 | 2 | 1 | ... |
| Student 2 ... | 4 | 1 | 5 | ... |
I want to make a list of the hole table to make some calculations with it.
My problem is, I know how to make a list. But this list is with more dimensions.
On my search through the I-Net I found lists with tuples, with dictionaries, with a classes :-( ...
I don´t want to use an array, because its not flexible enough.
I don´t know what kind of list I need, how to read/write from it, delete subjects...
It would be great to see your explanations on an example.
Thanks for your help
Naimish MakwanaPosted Sep 5, 2024, 9:04 AM
Certainly! There are several approaches you can take to handle multidimensional data in C#. Here are a couple of alternatives that might suit your needs:
1. Using a List of Dictionaries
If you prefer not to use classes, you can use a list of dictionaries. Each dictionary can represent a student and their subjects.
2. Using a DataTable
A
DataTableis another flexible option, especially if you’re dealing with tabular data like an Excel sheet.3. Using a List of Tuples
Tuples can be a simple way to store data without creating a full class.
Comparison of Approaches
Example: Using DataTable
Here’s how you can manipulate data in a
DataTable:Each approach has its pros and cons, so choose the one that best fits your specific needs and the complexity of your data operations.
Thanks
Hanif HefazPosted Sep 2, 2024, 8:36 PM
Welcome to the world of C#. Looks like you're looking to manage a list of students and their grades in different subjects. Given your requirements, using a class to represent each student and their grades would be a great approach. This way, you can easily add, remove, and modify grades for each student.
Here is how to do it in case if you don't know:
Main Program:
Using a class with a dictionary gives you flexibility to handle different subjects and their related grades dynamically. You can easily add or remove subjects and grades as needed. This approach will help you manage your data more effectively as you continue to learn C#. Happy coding!