XDocument声明失败

Ila*_*321 0 c# xml linq

我一直在编写一个使用的聊天程序System.Net.我也有一个配置XML文件%appdata%\.ilan,但是当我想声明一个新的XDocument类型变量时,Visual Studio Ultimate 2013不会将它识别为变量,当我完成整个变量时,它说get or set accessor expected.我在使用XDocument的同一个Studio中创建了一个不同的程序,它在那里工作!
我有System.Xml;,System.Xml.Linq;在顶部,所以我不知道我的代码有什么问题:

public void DefaultXML
{
    XDocument doc = new XDocument(
    new XDeclaration("1.0", "utf-8", "yes"),
    new XComment(" - IlanChat Settings File - "),
    new XElement("settings",
        new XElement("nick", "User")));
}
Run Code Online (Sandbox Code Playgroud)

我把它与我之前的程序进行了比较,语法是一样的.

Mic*_*Liu 5

您忘记在方法名称后面加上括号:

public void DefaultXML()   // <--
Run Code Online (Sandbox Code Playgroud)

如果没有括号,IDE会认为您正在声明属性而不是方法.这就是为什么它认为你错过了一个获取或设置访问器.