Please see an example of my code below:
public class ScrollableCheckboxList
{
public List<ScrollableCheckboxItem> listitems;
public void ScrollableCheckboxList<TModel>(IEnumerable<TModel> items, string valueField, string textField, string titleField) where TModel : class
{
listitems = new List<ScrollableCheckboxItem>();
foreach (TModel item in items)
{
Type t = typeof(TModel);
PropertyInfo[] props = new [] { t.GetProperty(textField), t.GetProperty(valueField), t.GetProperty(titleField) };
listitems.Add(new ScrollableCheckboxItem
{
text = props[0].GetValue(item, null).ToString(),
value = props[1].GetValue(item, null).ToString(),
title = props[2].GetValue(item, null).ToString()
});
}
}
}
The code produces the following error:
'ScrollableCheckboxList': member names cannot be the same as their enclosing type
This clearly means that there is a method in the class that has the same name as the class, but usually insinuates that the method is trying to return something (which is not allowed)
In my case, all I have done is declare a constructor - why would this be a problem?