1. C# / Говнокод #2986

    +115.2

    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
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    class TReadWrapper<TItemType>
        {
    		public static object item(string ItemString)
            {
    			if (typeof(TItemType) == typeof(double))
    				return Convert.ToDouble(ItemString);
                TDbg.Assert(false);
                return null;
            }
        };
    
        class TRead<TItemType>
        {
    		public static TItemType item(StreamReader BinaryStream)
            {
    			string ItemString = BinaryStream.ReadLine();
    			if (ItemString == null)
    				throw new Exception();
    			return (TItemType)TReadWrapper<TItemType>.item(ItemString);
            }
        };
    
    	class TFileToList<TListItem> : List<TListItem>
        {
            public TFileToList(string FileName)
            {
    			if(typeof(TListItem)==typeof(char))
    			{
    				StreamReader file = new StreamReader(FileName, Encoding.Unicode);
    				string FileData = file.ReadToEnd();
    				foreach (char item in FileData)
    					this.Add((TListItem)(object)item);
    				file.Close();
    				return;
    			};
    
    			StreamReader fileSource = new StreamReader(FileName, Encoding.Unicode);
    			try
                {
    				for (;;)
    					this.Add(TRead<TListItem>.item(fileSource));
    			}
    			catch
    			{
    			};
    			fileSource.Close();
            }
        }
    
        class TListToFile<TListItem>
        {
            static public void rewrite(string NameOfDestinationFile, List<TListItem> Source)
            {
    			if(typeof(TListItem)==typeof(char))
    			{
    				StreamWriter file = new StreamWriter(NameOfDestinationFile, false, Encoding.Unicode);
    				foreach (TListItem item in Source)
    					file.Write(item);
    				file.Flush();
    				file.Close();
    				return;
    			};
    
    			StreamWriter fileDestination = new StreamWriter(NameOfDestinationFile, false, Encoding.Unicode);
    			foreach (TListItem item in Source)
    				fileDestination.WriteLine(Convert.ToString(item));
    			fileDestination.Flush();
    			fileDestination.Close();
            }
        }

    Говногость, 11 Апреля 2010

    Комментарии (23)
  2. C# / Говнокод #2980

    +120

    1. 1
    2. 2
    foreach(char Enter in Environment.NewLine)
                  this.Add(Enter);

    Говногость, 10 Апреля 2010

    Комментарии (10)
  3. C# / Говнокод #2975

    +117.4

    1. 1
    int? ipLong = ip != null ? (int?)ip.Address : null;

    Вот так взялись отрицательные IP в базе. А главное-то, правильно переменную назвать!

    Rom@nych, 09 Апреля 2010

    Комментарии (16)
  4. C# / Говнокод #2967

    +144

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    List<Student> students = new List<Student>
            {
               new Student {LastName="Omelchenko", Scores= new List<int> {97, 72, 81, 60}},
               new Student {LastName="O'Donnell", Scores= new List<int> {75, 84, 91, 39}},
               new Student {LastName="Mortensen", Scores= new List<int> {88, 94, 65, 85}},
               new Student {LastName="Garcia", Scores= new List<int> {97, 89, 85, 82}},
               new Student {LastName="Beebe", Scores= new List<int> {35, 72, 91, 70}} 
            };

    Говногость, 08 Апреля 2010

    Комментарии (18)
  5. C# / Говнокод #2961

    +143.8

    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
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    using System;
    
    class MyGenericClass<T> {
      T ob;
    
      public MyGenericClass(T o) {
        ob = o;
      }
    
      public T getob() {
        return ob;
      }
    
      public void showType() {
        Console.WriteLine("Type of T is " + typeof(T));
      }
    }
    
    public class Test {
      public static void Main() {
        MyGenericClass<int> iOb;
    
        iOb = new MyGenericClass<int>(102);
    
        iOb.showType();
    
        int v = iOb.getob();
        Console.WriteLine("value: " + v);
    
        MyGenericClass<string> strOb = new MyGenericClass<string>("Generics add power.");
        strOb.showType();
        
        string str = strOb.getob();
        Console.WriteLine("value: " + str);
      }
    }

    как не надо юзать шаблоны классов

    sergylens, 08 Апреля 2010

    Комментарии (18)
  6. C# / Говнокод #2960

    +107.4

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    DirectoryEntry en = this.InitDirectoryEntry(ADObject);
    
    try
    {                   
         en.Parent.Children.Remove(en);
    }
    catch (Exception ex)
    {
               //??????????????????????????????
    }

    Удаление объекта в каталоге Active Directory

    dens, 08 Апреля 2010

    Комментарии (6)
  7. C# / Говнокод #2959

    +143

    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
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    using System;
    
    
    unsafe public struct program
    {
    	public static void Main()
    	{
    		test obj1 = new test();
    		obj1.call();
    	}
    	
    	public void Run()
    	{
    		Main();
    	}
    }
    
    unsafe struct test
    {
    	public void call()
    	{
    		program obj1 = new program();
    		program* p = &obj1;
    		p->Run();
    	}
    }

    сабж

    sergylens, 08 Апреля 2010

    Комментарии (19)
  8. C# / Говнокод #2958

    +142.6

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    using System;
    
    
    unsafe struct program
    {
    	static void Main()
    	{
    		program obj1 = new program();
    		program* p = &obj1;
    		p->Main();
    	}
    }

    попытка обратиться к члену структуры

    sergylens, 08 Апреля 2010

    Комментарии (6)
  9. C# / Говнокод #2957

    +143.4

    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
    using System;
    
    public unsafe class Starter {
        public static void Main() {
            char* pChar = stackalloc char[26];
            char* _pChar = pChar;
            for (int count = 0; count < 26; ++count) {
                (*_pChar) = (char)(((int)('A')) + count);
                ++_pChar;
            }
            for (int count = 0; count < 26; ++count) {
                Console.Write(pChar[count]);
            }
        }
    }

    Выделяем 26 символов в стеке, цикл присваивает буквы к каждому элементу

    sergylens, 08 Апреля 2010

    Комментарии (8)
  10. C# / Говнокод #2956

    +142.8

    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
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    using System;
    
    class program
    {
        unsafe public static void Foo(int* pa)
        {
            for (int* ip = pa; ip < (pa+5); ip++)
            {
                Console.WriteLine("value {0} at address: {1}", *ip, (int)ip);
            }
        }
       
        static void Main(string[] args)
        {
            unsafe
            {
                int* pa = stackalloc int[5];
                pa[0] = 12;
                pa[1] = 34;
                pa[2] = 56;
                pa[3] = 78;
                pa[4] = 90;
                Foo(pa);
            }
        }
    }

    Использование stackalloc для выделения памяти под массив

    sergylens, 08 Апреля 2010

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