Final answer:
To create the "ImportExportApp" Console Application project and meet the requirements mentioned, follow these steps:
1. Open your preferred integrated development environment (IDE) for C#, such as Visual Studio.
2. Create a new Console Application project and name it "ImportExportApp".
3. Inside the "ImportExportApp" namespace in the Program. cs file, create a new class called "Course" with the following three public auto-implemented properties:
```csharp
public class Course
{
public string CourseID { get; set; }
public string Name { get; set; }
public int Duration { get; set; }
}
```
4. Override the ToString () method in the Course class to return a string representation of all the values in the Course properties:
```csharp
public override string ToString ()
{
return $"Course ID: {CourseID}, Name: {Name}, Duration: {Duration}";
}
```
5. Add two static methods to the Course class:
a. WriteFile method: This method saves one or more Course objects to a specified file (Courses. json) as JSON. It takes two parameters: a list of Course objects to be saved and a string representing the file name.
```csharp
public static void WriteFile (List<Course> courses, string fileName)
{
using (StreamWriter writer = new StreamWriter (fileName))
{
foreach (Course course in courses)
{
string json = JsonConvert.SerializeObject (course);
writer.WriteLine (json);
}
}
}
```
b. ReadFile method: This method loads one or more Course objects from a specified text file (Courses. json) that is formatted in JSON. It takes one parameter: a string representing the file name to be loaded.
```csharp
public static List<Course> ReadFile (string fileName)
{
List<Course> courses = new List<Course>();
using (StreamReader reader = new StreamReader (fileName))
{
string line;
while ((line = reader.ReadLine ()) != null)
{
Course course = JsonConvert. DeserializeObject<Course>(line);
courses.Add (course);
}
}
return courses;
}
```
6. In the Main method of the Program. cs file, write a test harness to demonstrate that your code works as per the requirements. Follow these steps:
```csharp
static void Main (string[] args)
{
const string fileName = "Courses. json";
// Create a list of Course objects
List<Course> courses = new List<Course>()
{
new Course() { CourseID = "C001", Name = "Mathematics", Duration = 60 },
new Course() { CourseID = "C002", Name = "Science", Duration = 45 },
new Course() { CourseID = "C003", Name = "English", Duration = 90 }
};
// Invoke the WriteFile method to save the list of Course objects to the file
Course.WriteFile(courses, fileName);
// Invoke the ReadFile method to load the data from the file
List<Course> loadedCourses = Course.ReadFile(fileName);
// Display the information of the loaded Course objects
foreach (Course course in loadedCourses)
{
Console.WriteLine (course.ToString ());
}
}
```
7. Run the program, and it will create the "Courses. json" file and load the data from it. It will then display the information of the loaded Course objects in the console.
Step-by-step explanation:
The subject of this question is Computers and Technology and the grade level is College. The question is asking to create a Console Application project called "ImportExportApp" that includes a class called Course with three public auto-implemented properties. It also requires the Course class to override the ToString () method and have two static methods, WriteFile and ReadFile. The main method should test the functionality of the code by invoking WriteFile and ReadFile methods and displaying the information of the Course objects loaded from the file.
Make sure to follow the guidelines mentioned, including adhering to C# naming conventions and not changing any behavior, property names, method names, or identifiers.