Posts

Showing posts with the label code-review

Finding an item in a complex object

Finding an item in a complex object I have a sequence of elements string: new string { "A", "B", "C", "D" } And there is also an object consisting of such several sequences object: List<Test> obj = new List<Test>() { new Test() {Lists = new List<string>() { "A", "B" } }, new Test() {Lists = new List<string>() { "A", "C" } }, new Test() {Lists = new List<string>() { "C" } } }; I want to find the missing element ( "D" ) in all object collections. That's what I got: private static List<string> FindeMissingElements() { string nonExistentElement = null; List<string> nonExistentElements = new List<string>(); foreach (var elemArr in arr) { foreach (var elemObj in obj) { if (elemObj.Lists.Any(a => a.Contains(elemArr))) { nonExistentElement = null; ...