I want to return an anonymous data retreived from a query in Linq. I dont know which kind of List<> return because the data is “var” anonymous.
public List<?????> QueryXmlUserLogin()
{
var data = from item in XDocumentObj.Descendants("User_Data")
select new
{
user = item.Element("user").Value,
password = item.Element("password").Value,
};
data.ToList();
return ????
Two data types come to mind, a
Tuple<string, string>or aKeyValuePair<string, string>depending on their intended usage:Using these however, can often hide the meaning of return types. Since the method is public, you may be better creating a new class for the job:
As an aside, (based on the variable names) storing passwords in plaintext should not be done. Apologies if I’m incorrectly interpreting the variables or your example is contrived, but if anyone stumbles across this post – a hash of the password (and unique salt) should be stored rather than the password in plaintext.