vicky vicky - 1 year ago 165
ASP.NET (C#) Question

how to check if a string value exists in ReportParameter list c#

I have a ReportParameter list called

with few values.

List<ReportParameter> lstParam = new List<ReportParameter>();
ReportParameter rpm = new ReportParameter();
rpm.Name = "Department";
rpm.Name = "Location";

ReportParameter is used from reporting services rdlobject model

Now I need to check if the list has a specific string value and the below code doesn't work for 'ReportParameter' list.

var matchingvalues = !lstParam.Where(stringToCheck => stringToCheck.Contains(stringValue));

if (!lstParam.Any(str => str.Contains(stringValue)))


Both the above statement didn't help and I get the below error.

'ReportParameter' does not contain a definition for 'Contains' and the best extension
method overload 'Queryable.Contains<string>(IQueryable<string>,string)'
requires a receiver of type 'IQueryable<string>'

ReportParameter class:

public class ReportParameter : ReportObject, INamedObject
public ReportParameter();

public bool AllowBlank { get; set; }
public DataTypes DataType { get; set; }
public DefaultValue DefaultValue { get; set; }
public bool Hidden { get; set; }
public bool MultiValue { get; set; }
public string Name { get; set; }
public bool Nullable { get; set; }
public ReportExpression Prompt { get; set; }
[XmlChildAttributeAttribute("Prompt", "LocID", "")]
public string PromptLocID { get; set; }
public UsedInQueryTypes UsedInQuery { get; set; }
public ValidValues ValidValues { get; set; }

protected override bool RdlSemanticEqualsCore(ReportObject rdlObj, ICollection<ReportObject> visitedList);

Really appreciate any suggestions.

Answer Source

If you want to check only if there ia any item that satisifes your condition, can you please try this code

bool matchingvalues = lstDSParameter.SelectMany(stringToCheck => stringToCheck.Name.Contains(stringValue) || stringToCheck.PromptLocID.Contains(stringValue)).ToList().Count > 0