fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using System.Linq;
  5.  
  6. public class Test
  7. {
  8. public static void Main()
  9. {
  10. // your code goes here
  11.  
  12. List<MyObject> objects = new List<MyObject> {
  13. new MyObject { Id = 1, FirstName = "Bob", LastName = "Green" },
  14. new MyObject { Id = 2, FirstName = "", LastName = "Black" },
  15. new MyObject { Id = 3, FirstName = "Joe", LastName = "" },
  16. new MyObject { Id = 4, FirstName = null, LastName = "White" },
  17. new MyObject { Id = 5, FirstName = "Mike", LastName = "Brown" }
  18. };
  19.  
  20. var stringProperties = typeof(MyObject)
  21. .GetProperties()
  22. .Where(p => p.PropertyType == typeof(string))
  23. .ToArray();
  24.  
  25. objects.RemoveAll(o =>
  26. stringProperties.Any(p => String.IsNullOrEmpty((string)p.GetValue(o, null))));
  27.  
  28. foreach(var obj in objects)
  29. Console.WriteLine("{0} {1} {2}", obj.Id, obj.FirstName, obj.LastName);
  30.  
  31. }
  32. }
  33.  
  34. public class MyObject
  35. {
  36. public int Id { get; set; }
  37. public string FirstName { get; set; }
  38. public string LastName { get; set; }
  39. }
Success #stdin #stdout 0.05s 34088KB
stdin
Standard input is empty
stdout
1 Bob Green
5 Mike Brown