How can you create a class whose objects can be written to and read from data files? Show an example.

What will be an ideal response?

To create a class that can be serialized, you mark it with the [Serializable] attribute. In a class marked with the [Serializable] attribute, every instance variable must also be serializable. By default, all C# simple data types are serializable, including strings. However, if your class contains fields that are more complex data types, you must check the declaration of those classes to ensure they are serializable. By default, array objects are serializable. However, if the array contains references to other objects, such as Dates or Students, those objects must be serializable.
The example should be similar to the following:
[Serializable]
class Employee
{
public string Name;
public double Salary;
}

Computer Science & Information Technology

You might also like to view...

What web browser feature would be particularly useful when using public computers?

a. Pinned tabs b. Session restore c. Privacy browsing d. all of the above

Computer Science & Information Technology

The fastest broadband Internet service is usually

a. fiber-optic. b. DSL. c. cable. d. satellite.

Computer Science & Information Technology