XML Serialization in C# with examples

Let, I have a object in C# and I need to serialize the object to XML. My class is look like:

And I Initialize object :

Here is one simple example to serialize in XML using XmlSerializer:

Suppose, I have to serialize multiple types then we should make a generic method like to support all types:

The output is: