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...

When an object is ____, the remaining components are automatically grouped.

A. united B. divided C. compounded D. masked

Computer Science & Information Technology

To insert a row in a worksheet, right-click the row heading area and click Add on the resulting shortcut menu

Indicate whether the statement is true or false

Computer Science & Information Technology

Public key encryption utilizes a pair of encryption keys obtained through ____ .

a. Verizon b. Microsoft c. an ISP d. a Certificate Authority

Computer Science & Information Technology

____________________ access refers to individuals gaining access to a computer, network, file, or other resource without permission.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology