user4912134 user4912134 - 2 months ago 9x
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


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>();