Using the generic type 'System.Collections.Gen

2020-04-23 07:32发布

问题:

I've two method that are the code from here http://www.rajbandi.net/fixing-ssrs-report-viewer-control-date-picker-in-google-chrome/#comment-988, Then i apply the following code to my project i have a problem.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Reporting.WebForms;
using System.Configuration;
using System.Web.SessionState;
using RLISDev.Models;
using RLISDev.BaseObjects;
using System.Web.Mvc;
using RLISDev.Extensions;
using RLISDev.Annotations;
using System.Collections;
protected override void OnPreRender(EventArgs e) {
    base.OnPreRender(e);
    DatePicker1.Value = string.Join(",", (new > List(GetDateParameters()).ToArray()));
}
private IEnumerable GetDateParameters() {
    // I'm assuming report view control id 
    // as reportViewer
    foreach(ReportParameterInfo info in
        ReportViewer1.ServerReport.GetParameters()) {
        if (info.DataType ==
            ParameterDataType.DateTime) {
            yield
            return string.Format("[{0}]",
                info.Prompt);
        }
    }
}

And I got error here

List(GetDateParameters()).ToArray()) Using the generic type 'System.Collections.Generic.List' requires 1 type arguments

I am not sure what i am missing.

回答1:

You have to give it a type argument, as it is a generic class:

var test = new List<DateTime>();

Depending on the return type of GetDateParameters(); you want something like:

DatePicker1.Value = string.Join(",", (new List<DateTime>(GetDateParameters()).ToArray()));


回答2:

Note : i am modified my code

protected override void OnPreRender(EventArgs e) {
     base.OnPreRender(e);
     DatePicker1.Value = string.Join(",", (GetDateParameters().ToList().ToArray()));
 }
 private IEnumerable < string > GetDateParameters() {
     // I'm assuming report view control id as reportViewer
     foreach(ReportParameterInfo info in ReportViewer1.ServerReport.GetParameters()) {
         if (info.DataType == ParameterDataType.DateTime) {
             yield return string.Format("[{0}]", info.Prompt);
         }
     }
 }

and this is worked.



标签: c# generics