Others have considered overriding ToString() , so I will not rephrase this information. Moreover, at your request:
Can someone please help me and tell me how to use the structures in the example above.
See MSDN: Structural Design
First, your structure is volatile. Inevitable structures are not always the best solution, but they should be considered ... see the article I use for in the <class> structure in the Dictionary class . However, I would define a basic requirement: does the structure require variability? In other words, will there be a student name, unit number or label change after creating the instance?
Secondly, if the requirement is to have a StudentDetails collection, the array is in order:
Note: exception handling is not considered in this example; for example, incrementing outside the array.
In the previous example, you could change any of the properties of the StudentDetails structure after creating the instance. Structures become safer with immutability:
public struct StudentDetails { public readonly string unitCode; //eg CSC10208 public readonly string unitNumber; //unique identifier public readonly string firstName; //first name public readonly string lastName;// last or family name public readonly int studentMark; //student mark // use a public constructor to assign the values: required by 'readonly' field modifier public StudentDetails(string UnitCode, string UnitNumber, string FirstName, string LastName, int StudentMark) { this.unitCode = UnitCode; this.unitNumber = UnitNumber; this.firstName = FirstName; this.lastName = LastName; this.studentMark = StudentMark; } }
This requires changing how you add the details object to the students array:
void AddStudentDetails(string unitCode, string unitNumber, string firstName, string lastName, int studentMark) { students[indexer] = new StudentDetails(unitCode, unitNumber, firstName, lastName, studentMark);
Consider the requirements for structure and design.