I have class Synonym, below:
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);
}
}
}
}
in main program, i have code below:
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);
}
but, there’s error: IN MAIN PROGRAM : “FROM S IN …..SELECT S”
===========>>Value cannot be null. AND Parameter name: source
I guess there’s error in class
public List<string> Sinonim
{
get{ return _sinonim;}
}
That would indicate that your private list variable is never being assigned, which it is not.
List<string> _sinonim = new List<string>();This hides the private instances because the names are the same. Change that line in your constructor to this and it should work
_sinonim = new List<string>();