Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, February 15, 2012 3:46 PM
I'm trying to careate a class called ChartBuilder. Getting error.Please help me
private IList<Series> BuildChartSeries()
{
//List<Series> seriresList = new List<Series>();
object seriesList = new List<Series>();
for (int i = 0; i <= _numberOfSeries - 1; i++)
{
Series series = new Series
{
ChartType = SeriesChartType.Column,
Palette = ChartColorPalette.Pastel,
MarkerSize = 10
};
seriesList.Add(series);
}
CustomizeChartSeries(seriesList);
return seriesList;
}
private virtual void CustomizeChartSeries(IList<Series> seriesList)
{
}
Getting error here in these lines
1. seriesList.Add(series);
'object' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
2. CustomizeChartSeries(seriesList);
The best overloaded method match for 'ChartBuilder.CustomizeChartSeries(System.Collections.Generic.IList<System.Web.UI.DataVisualization.Charting.Series>)' has some invalid arguments
3. return seriesList;
Cannot implicitly convert type 'object' to 'System.Collections.Generic.IList<System.Web.UI.DataVisualization.Charting.Series>'. An explicit conversion exists (are you missing a cast?)
All replies (3)
Wednesday, February 15, 2012 5:45 PM âś…Answered
The error message says it all. seriesList is of type object. You have attempted to call a method named Add on a variable of type object. The object type does not have a method called Add. Or in brief - 'object' does not contain a definition for 'Add'
Why have you declared seriesList to be of type object? Why have you commented out the correct (apart from the typo in the variable name) declaration?
Thursday, February 16, 2012 1:46 AM
Hi,
Change this statement object seriesList = new List<Series>(); to List<Series> seriesList = new List<Series>();
Thanks
Harshad Patel
Thursday, February 16, 2012 2:57 AM
Why have you declared seriesList to be of type object? Why have you commented out the correct (apart from the typo in the variable name) declaration?
Paul, I'm only guessing here, but i wonder whether the OP has confused object with var?