user4912134 user4912134 - 1 year ago 127
ASP.NET (C#) Question

System.Collections.Generic.List<string>' does not contain a definition for 'add'

I am using the below code

public HttpResponseMessage Getdetails([FromUri] string[] Column)
List<string> selectionStrings;
var colDict = new Dictionary<string, string>()
foreach (string col in Column)
string selector = colDict[col];
selectionStrings.add(string.Format("{0} AS {1}", selector, col));
var strQuery = string.Format(@"SELECT {0}

But getting the error in

selectionStrings.add(string.Format("{0} AS {1}", selector, col));


'System.Collections.Generic.List' does not contain a
definition for 'add' and no extension method 'add' accepting a first
argument of type 'System.Collections.Generic.List could be
found (are you missing a using directive or an assembly reference?)

I tried adding
using System.Collections.Generic.List
but it doesn't work

Answer Source

Try using Add instead of add,

selectionStrings.Add(string.Format("{0} AS {1}", selector, col));

also initialize selectionStrings , currently your code will throw an exception

List<string> selectionStrings = new List<string>();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download