Start new console and create one class like this:

public class IndexerClass
{
	private string[] myData;

	public string this[string myTest]
	{
		get
		{
			return "Test get";
		}
	}
}


Now if Main method looks like this:

class Program
{
	static void Main(string[] args)
	{
		IndexerClass myInd = new IndexerClass();

		Console.WriteLine(myInd["A test"]);

		Console.ReadKey();
	}
}


Result would be something like this:

Test get

Example you can download from here

To use "using" you need to have implementation IDisposable interface, so here is how my ViewModel look like:

namespace UsingExample.ViewModel
{
  using System;
  using System.Windows;

  public class UsingExampleViewModel
  {
    public string UsingExampleTest { get; set; }

    public UsingExampleViewModel()
    {
      using (UsingExampleClassTest aaa = new UsingExampleClassTest())
      {
        aaa.myTest = "rrr";
      }
      UsingExampleTest = "test";
    }
  }

  public class UsingExampleClassTest: IDisposable
  {
    public string myTest { get; set; }

    public void Dispose()
    {
      MessageBox.Show("Die object!");
    }
  }

}

XAML:

<Window x:Class="UsingExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:viewModel="clr-namespace:UsingExample.ViewModel"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.Resources>
            <viewModel:UsingExampleViewModel x:Key="UsingExampleViewModel" />
        </Grid.Resources>
        <TextBox DataContext="{StaticResource UsingExampleViewModel}" Text="{Binding UsingExampleTest}"/>
    </Grid>
</Window>

Example project you can download from here.

Let's say we want to create xml like this:

<?xml version="1.0" encoding="utf-8"?>
<project>
  <menu bg_img="">
    <mnu_item txt="Menu item 1" anotherAttribute="another attribute 1">
      <sub_item txt="Sub item 1" articleId="1" />
    </mnu_item>
	
    <mnu_item txt="Menu item 2" anotherAttribute="another attribute 2">
      <sub_item txt="Sub item 2" articleId="2" />
    </mnu_item>
	
  </menu>
</project>

Serialization

First we need model:

  [XmlRoot("project")]
  public class Project
  {
    [XmlElement(ElementName = "menu")]
    public Menu Menu { get; set; }
  }

  public class Menu
  {
    [XmlAttribute("back_image")]
    public string backImage {get; set;}

    [XmlElement(ElementName = "mnu_item")]
    public List<MenuItem> MenuItem { get; set; }
  }

  public class MenuItem
  {
    [XmlAttribute("txt")]
    public string Txt { get; set; }

    [XmlAttribute("anotherAttribute")]
    public string AnotherAttribute { get; set; }

    [XmlElement("sub_item")]
    public SubItem SubItem { get; set; }
  }

  public class SubItem
  {
    [XmlAttribute("txt")]
    public string Txt { get; set; }

    [XmlAttribute("articleId")]
    public string ArticleId { get; set; }
  }

ViewModel looks like this:

Project serializedProject = new Project();

serializedProject.Menu = new Menu();
serializedProject.Menu.backImage = string.Empty;

MenuItem menuItem = new MenuItem();

menuItem.Txt = "Menu item 1";
menuItem.AnotherAttribute = "another attribute 1";

menuItem.SubItem = new SubItem();
menuItem.SubItem.Txt = "Sub item 1";
menuItem.SubItem.ArticleId = "1";

serializedProject.Menu.MenuItem = new List<MenuItem>();

serializedProject.Menu.MenuItem.Add(menuItem);

menuItem = new MenuItem();

menuItem.Txt = "Menu item 2";
menuItem.AnotherAttribute = "another attribute 2";

menuItem.SubItem = new SubItem();

menuItem.SubItem.Txt = "Sub item 2";
menuItem.SubItem.ArticleId = "2";

serializedProject.Menu.MenuItem.Add(menuItem);

TextWriter txtWriter = new StreamWriter(Path.ChangeExtension(System.Reflection.Assembly.GetEntryAssembly().Location, ".xml"));

XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");

XmlSerializer xmlSerializer = new XmlSerializer(typeof(Project), "");
xmlSerializer.Serialize(txtWriter, serializedProject, ns);
txtWriter.Close();

Notice lines:

XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
...
xmlSerializer.Serialize(txtWriter, serializedProject, ns);

Without these lines our XML would look like this:

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

Then in model, line, for example:

[XmlAttribute("back_image")]

Means that our attribute will be named as "back_image" in our XML.

Also, notice line:

Path.ChangeExtension(System.Reflection.Assembly.GetEntryAssembly().Location, ".xml")

With

System.Reflection.Assembly.GetEntryAssembly().Location

We are geting location of our exe file, and with method Path.ChangeExtension we are changing our file extension to XML.

Linq to XML

For linq to XML we don't need model, only XElement, so my code looks like this:

XElement myLinq2XML = 
	new XElement(
		"project",
		new XElement(
			"menu",
			new XAttribute("back_image", string.Empty),
			new XElement(
				"mnu_item",
				new XAttribute("txt", "Linq2XML item 1"),
				new XAttribute("anotherAttribute", "another attribute 1"),
				new XElement("sub_item", 
					new XAttribute("txt", "Sub item 1"), 
					new XAttribute("articleId", "1")
				)
			),
			new XElement(
				"mnu_item",
				new XAttribute("txt", "Linq2XML item 2"),
				new XAttribute("anotherAttribute", "another attribute 2"),
				new XElement("sub_item", 
					new XAttribute("txt", "Sub item 2"), 
					new XAttribute("articleId", "2")
				)
			)
		)
	);

Example project you can download from here.

Serialization and deserialization. To write this article I was using this web page. First lets serialize the XML. Idea is to create xml like

<?xml version="1.0" encoding="utf-8"?>
<definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <channels>
    <channel>
      <urn>test</urn>
    </channel>
  </channels>
</definitions>

So, first we have to prepare model, and looks like:

public class definitions
{
	public List<channel> channels { get; set; }
}

public class channel
{
	public string urn { get; set; }
}

Now serialization:

definitions serializeObject = new definitions();
channel channel = new channel();
channel.urn = "test";
serializeObject.channels = new List<channel>();
serializeObject.channels.Add(channel);

XmlSerializer xmlSerializer = new XmlSerializer(typeof(definitions));
TextWriter txtWriter = new StreamWriter(@"d:\temp\MyTest.xml");
xmlSerializer.Serialize(txtWriter, serializeObject);
txtWriter.Close();

That is all about serialization. Now we well deserialize same XML:

XmlSerializer xmlSerializer = new XmlSerializer(typeof(definitions));
using (FileStream fileStream = File.OpenRead(@"d:\temp\MyTest.xml"))
{
	definitions channelDefinitions = (definitions)xmlSerializer.Deserialize(fileStream);
	ChannelModels = channelDefinitions.channels;
}

Example project you can download from here.

That's all folks!