Create a console application:
- Open Visual Studio 2010 by going Start | All Programs | Microsoft Visual Studio 2010 | Right click on Microsoft Visual Studio 2010 and click on Run as administrator.
- Go to File tab, click on New and then click on Project.
- In the New Project dialog box, expand the Visual C# node, and then select the Windows node.
- In the Templates pane, select Console Application.
- Enter the Name as LINQ and then click OK.
- In the solution explorer, right click on the solution and then click on Properties.
- Select the Application tab, check whether “.Net Framework 3.5” is selected for Target Framework.
- Select the Build tab, check whether “Any CPU” is selected for Platform Target.
Add the following References:
- System.Xml.Linq.dll
Add the following Namespace:
- Using System.Xml.Linq;
Program.cs:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Linq; namespace LinqSamples { class Program { static void Main(string[] args) { XElement employees = XElement.Parse( @"<EmployeeDetails> <Employee> <Name>Vijai Anand</Name> <Id>206</Id> <Designation>Associate</Designation> <Department>SharePoint</Department> <Location>Bangalore</Location> </Employee> </EmployeeDetails>"); Console.WriteLine(employees); Console.ReadLine(); } } }
|