我有类同义词,如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace Examples.NET
{
public class Synonym
{
private string _kata;
private List<string> _sinonim;
public String Kata
{
get { return _kata; }
}
public List<string> Sinonim
{
get
{
return _sinonim;
}
}
public Synonym(string kata)
{
_kata = kata;
List<string> _sinonim = new List<string>();
XDocument xDoc = XDocument.Load("http://www.stands4.com/services/v2/syno.php?uid=2319&tokenid=LSRyvL5mGsHpEi4&word=" + kata);
var sinonim = from isi in xDoc.Descendants("result")
select new
{
sinom = isi.Descendants("synonyms").First().Value
};
foreach (var s in sinonim)
{
_sinonim.Add(s.sinom);
}
}
}
}
在主程序中,我有以下代码:
Synonym Syn = new Synonym("buy");
System.Console.WriteLine(Syn.Kata);
var sinom = from s in Syn.Sinonim
select s;
foreach (var item in sinom)
{
System.Console.WriteLine("data: " + item);
}
但是,出现错误:在主程序中:“FROM S IN .....SELECT S”===========>>值不能为空。AND 参数名称:source
我想课堂上有错误
public List<string> Sinonim
{
get{ return _sinonim;}
}