I see many online samples talking about Generics List<T>.
I’m just not sure if T is just a way for the narrator to define “any type” or if I can actually use the syntax List<T> to define a property that can receive any type of LIST.
If not, then what is the right way to define a property that can be populated with either List<MyType>, or List<YourType> or List<AnyType> ??
The reason I’m asking is also because on my WebService that property is giving me the following error:
The type or namespace name 'T' could not be found (are you missing a using directive or an assembly reference?)
and off course I already have the using System.Collections.Generic; on top.
SOURCE CODE:
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
namespace StackOverflow
{
[ServiceContract]
public interface IDbSync
{
[OperationContract]
int UploadTable(SecurityToken token, TableData table);
}
[DataContract]
public class SecurityToken
{
string id = "";
string token = "";
[DataMember]
public string ID
{
get { return id; }
set { id = value; }
}
[DataMember]
public string Token
{
get { return token; }
set { token = value; }
}
}
[DataContract]
public class TableData
{
List<T> data;
string tableName = "";
[DataMember]
public string TableName
{
get { return tableName; }
set { tableName = value; }
}
[DataMember]
public List<T> Data
{
get { return data; }
set { data = value; }
}
}
}