I’m sure this is easy. Infact I’m sure I’ve done this before…
I have a class of MyClass which has 2 parameters TheString and SomeInt
Somewhere, in another class I declare an List<MyClass> MyClassList and a List<String> StringList
Both have the same number of items. I want this to set all “TheStrings” in each MyClass from MyClassList equal to the corresponding String from StringList
I set MyClassList = StringList
Now I know this wont work because they’re different types. I think I’ve got to overload the assignment (=) operator but I can’t see how this is done. I suppose I could always provide a method to call from MyClass, but that isn’t quite so elegant. What would be the most elegant solution?
Thanks
Thomas
You can’t overload the = operator. You could do an implicit conversion, example from MSDN:
However in case of lists I think the best solution is to use LINQ: