tags:

views:

32

answers:

1

what is wrong with such code

 public List<SearchItem> Search(string find)
        {


            return (from i in _dataContext.News where i.Text.Contains(find) select new SearchItem { ControllerAction = "test", id = i.Id.ToString(), LinkText = "test" }).ToList();
        }

public struct SearchItem
    {
        public string ControllerAction;
        public string LinkText;
        public string id;
    }
+1  A: 
new SearchItem() {...}  

//no .ToList() or else you don't need the class (s/b a class with property get/set), you could just say new

machine elf
can you explaine about no ToList and get/set ?
kusanagi
as you ca n see it is not class but struct, i need class?
kusanagi
I'm learning the art of quick response... The only must have, due to the method sig, is ToList<SearchItem>(). You could use a struct with public members but it's a "philosophical issue" and it would limit your data binding and versioning options. Classes with properties are more the "norm" esp when public. In addition to assignment via { } you could use ctor methods (in parenthesis). Having an implicit/explicit parameterless ctor available is advantageous for classes used with collections or generic constraints, (but struct need an implicit parameterless ctor). Use struct if it makes sense.
machine elf