public CD[] GetCDCatalog()
{
XDocument docXML =
XDocument.Load(Server.MapPath("mydata.xml"));
var CDs =
from cd in docXML.Descendants("Table")
select new CD
{
title = cd.Element("title").Value,
star = cd.Element("star").Value,
endTime = cd.Element("endTime").Value,
};
return CDs.ToArray<CD>();
}
I am calling this function on page load
ie. string[] arr = GetCDCatalog();
but this is giving Error Cannot implicitly convert type ‘Calender.CD[]’ to ‘string[]’
Please suggetst how can i call function on page load which return type is array.
Your method is declared to return a
CD[], and as the compiler has told you, you can’t convert from aCD[]to astring[]. Call it like this instead:If you need to convert to a string array then you could use something like this:
Or if you don’t really need it in an array, you could just use: