Using attributes

A declarative way of associating information to code can be done via attributes. However, only a few attributes can be used on every type. Instead, they are used for specific types. Attributes on any type can be specified by using square brackets, [], on top of the type that we want to apply.

Let's take a look at the following code. Generally, we see the Serializable attribute when we want to serialize an object to the binary or XML formats. In real-world applications, when we need to transfer a large object over the wire, we serialize an object into one of the aforementioned formats and then send it. The serialize attribute on a class enables runtime to allow converting the object to binary or XML or any format required ...

Get Programming in C#: Exam 70-483 (MCSD) Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.