C# XDocument.Load方法在XDocument中不存在
我一直在用Linq加载新的XML文档。这是我的密码:C# XDocument.Load方法在XDocument中不存在,c#,.net,xml,linq,linq-to-xml,C#,.net,Xml,Linq,Linq To Xml,我一直在用Linq加载新的XML文档。这是我的密码: using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Wi
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml.Linq;
namespace Project
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
XDocument doc = new XDocument.Load("001.xml");
}
}
}
我得到的回报是,“Load”方法在“XDocument”类型上不存在。
这真的很奇怪,因为我认为“使用System.Xml.Linq”就足够了。
我想使用Linq,因为我有一个复杂的XML,我认为使用Linq浏览所有元素更容易。我正在使用Visual Studio 2015社区。是一种静态方法。您的代码在语法上不正确-您似乎试图调用构造函数(通过使用new
),但缺少一些括号
要调用静态方法,只需执行以下操作:
var doc = XDocument.Load("001.xml");
这是一种静态方法。您的代码在语法上不正确-您似乎试图调用构造函数(通过使用new
),但缺少一些括号
要调用静态方法,只需执行以下操作:
var doc = XDocument.Load("001.xml");
是XDocument
的静态方法。您的代码尝试实例化一个新的XDocument
对象(位于newxdocument()
),并调用Load
作为其实例方法
将代码更改为:
XDocument doc = XDocument.Load("001.xml"); // without "new"
是XDocument
的静态方法。您的代码尝试实例化一个新的XDocument
对象(位于newxdocument()
),并调用Load
作为其实例方法
将代码更改为:
XDocument doc = XDocument.Load("001.xml"); // without "new"
Load是一种静态方法,只需以这种方式使用(不使用新的):
XDocument.Load是一种静态方法,只需这样使用(不使用新的):
解决了,我只是个傻瓜。谢谢大家!解决了,我只是个傻瓜。谢谢大家!