1. Список говнокодов пользователя Jopa123

    Всего: 1

  2. C# / Говнокод #6019

    +116

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    // Method that returns anonymous type as object
    object ReturnAnonymous() {
      return new { City="Prague", Name="Tomas" };
    }
    
    void Main() {
      // Get instance of anonymous type with 'City' and 'Name' properties
      object o = ReturnAnonymous();
    
      // This call to 'Cast' method converts first parameter (object) to the
      // same type as the type of second parameter - which is in this case 
      // anonymous type with 'City' and 'Name' properties
      var typed = Cast(o, new { City="", Name="" });
      Console.WriteLine("{0}, {1}", typed.City, typed.Name)
    }
    
    // Cast method - thanks to type inference when calling methods it 
    // is possible to cast object to type without knowing the type name
    T Cast<T>(object obj, T type) {
      return (T)obj;
    }

    via http://social.msdn.microsoft.com/forums/en-US/linqprojectgeneral/thread/c1c179bb-ea88-4633-970a-947f0dd1e71f/

    Jopa123, 18 Марта 2011

    Комментарии (9)