Click here to Skip to main content
15,125,459 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi everybody,
Does anybody there can help me with tha traslation of the next code C# to VB.NET? I'm working in WPF Application (VB.NET).
NOTE: I have a problem with the part: ' // Create the query

var rowsFromFile = from c in XDocument.Load(
                           "MyData.xml").Elements lang="sql">"Data").Elements("Rows").Elements("Row")
                                  select c;

I can't found the traslation.

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace ListViewTest
    public class MyData
        /// <summary>
        /// Saves items to MyData.xml file in bin folder.
        /// </summary>
        /// <param name="items"></param>
        public void Save(System.Windows.Data.CollectionView items)
            XDocument xdoc = new XDocument();

            XElement xeRoot = new XElement("Data");
            XElement xeSubRoot = new XElement("Rows");

            foreach (var item in items)
                ListViewData lvc = (ListViewData)item;

                XElement xRow = new XElement("Row");
                xRow.Add(new XElement("col1", lvc.Col1));
                xRow.Add(new XElement("col2", lvc.Col2));



        /// <summary>
        /// Gets data from MyData.xml as rows.
        /// </summary>
        /// <returns></returns>
        public IEnumerable<object> GetRows()
            List<ListViewData> rows = new List<ListViewData>();

            if (File.Exists("MyData.xml"))
                // Create the query
                var rowsFromFile = from c in XDocument.Load(
                                   select c;

                // Execute the query
                foreach (var row in rowsFromFile)
                    rows.Add(new ListViewData(row.Element("col1").Value,
            return rows;

Updated 8-Oct-13 20:48pm
[no name] 16-Jul-13 15:39pm
"// Create the query" is the problem or the nonexistent var keyword is the problem?
alonetmr 16-Jul-13 16:19pm
Yes, i have a problem with "var", apparently it doesn't exist. Why?
[no name] 16-Jul-13 21:35pm
Why? Because the designers of the VB.NET language did not include it. If you want to know specifically why they did not include it, you would need to go ask Microsoft.
alonetmr 16-Jul-13 16:22pm
When i do the convertion to VB.NET, i have an error with var. I take this example of:
[no name] 16-Jul-13 21:35pm
So change "var" to a data type type that VB.NET supports.
Nicholas Marty 18-Jul-13 5:54am
The functionality of var hower does exist. Known as "Option Infer":

1 solution

Instead asking others to do your job for you (how else can one understand your request), you should learn the ways to do such translations automatically.

Good luck,
The-vister 26-Sep-13 2:43am
I know that there are online converters and i know vb syntax and c# syntax and i can convert without any converter but in this code i am using lightswitch and i am new with it, and in the code there are xaml code it is the first time that is see xaml code in vb class. and here is my proble how to convert this xaml to use it in c#???? and thx for your help
XAML is the same, it does not depend on C# or VB.NET.
Suvendu Shekhar Giri 1-Dec-15 22:04pm
5Ed !
Thank you, Suvendu Shekhar.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900