user4912134 user4912134 - 3 months ago 15
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>()
{
{"CATEGORY", "STCD_PRIO_CATEGORY_DESCR.DESCR"},
{"SESSION_NUMBER", "STRS_SESSION3.SESSION_NUM"},
{"SESSION_START_DATE","Trunc(STRS_SESSION3.START_DATE)"}
};
foreach (string col in Column)
{
string selector = colDict[col];
selectionStrings.add(string.Format("{0} AS {1}", selector, col));
}
var strQuery = string.Format(@"SELECT {0}
from STCD_PRIO_CATEGORY");
}


But getting the error in

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


saying


'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

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