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

    +125

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    private void goSimpleButton_Click(object sender, EventArgs e)
    {
        if (Properties.Settings.Default.username == "edodonova")
        {
            if (MessageBox.Show("Открывать?", "На всякий случай спрашиваем :-)", MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                return;
            }
        }

    someone, 19 Мая 2013

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

    +123

    1. 1
    2. 2
    3. 3
    4. 4
    [Obsolete("Непонятный хлам")]
    public static class CalendarHelper
    {
    }

    musuk, 16 Мая 2013

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

    +139

    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
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    class MainClass
        { 
            public static char[,] titato = new char[3, 3] { { ' ', ' ', ' ' }, { ' ', ' ', ' ' }, { ' ', ' ', ' ' } };
            static bool CheckWin(char s)
            {
                if ((titato[0, 0] == titato[1, 1] & titato[1, 1] == titato[2, 2] & titato[0, 0] != ' ') ||
                      (titato[0, 1] == titato[0, 2] & titato[0, 2] == titato[0, 0] & titato[0, 1] != ' ') ||
                       (titato[1, 1] == titato[1, 2] & titato[1, 2] == titato[1, 0] & titato[1, 1] != ' ') ||
                        (titato[2, 1] == titato[2, 2] & titato[2, 2] == titato[2, 0] & titato[2, 1] != ' ') ||
                         (titato[1, 0] == titato[2, 0] & titato[2, 0] == titato[0, 0] & titato[1, 0] != ' ') ||
                          (titato[1, 1] == titato[2, 1] & titato[2, 1] == titato[0, 1] & titato[1, 1] != ' ') ||
                           (titato[1, 2] == titato[2, 2] & titato[2, 2] == titato[0, 2] & titato[1, 2] != ' ') ||
                            (titato[2, 0] == titato[1, 1] & titato[1, 1] == titato[0, 2] & titato[2, 0] != ' '))
                {
                    return true;
                }
                return false;
            } 
            public static void PrintTicTacToe(char s)
            { 
                Console.Clear();            
                Console.Write(" ");            
                Console.BackgroundColor = ConsoleColor.White; 
                for (int i = 0; i < titato.GetLength(0); i++)            {
                     Console.Write(" {0} ", i); 
                } 
                Console.WriteLine(); 
                for (int i = 0; i < titato.GetLength(0); i++)            {
                     Console.BackgroundColor = ConsoleColor.White;
                     Console.Write("{0}", i);
                     for (int j = 0; j < titato.GetLength(1); j++)                { 
                        Console.BackgroundColor = ConsoleColor.Black;
                         if (titato[i, j] == 'x')                    {
                            Console.ForegroundColor = ConsoleColor.Red; 
                        }
                        else if (titato[i, j] == 'o')                    { 
                            Console.ForegroundColor = ConsoleColor.Green; 
                        } 
                        else                    { 
                            Console.ForegroundColor = ConsoleColor.Black;
                         }
                         Console.Write(" {0} ", titato[i, j]); 
                    } 
                    Console.WriteLine(); 
                } 
                Console.BackgroundColor = ConsoleColor.White; 
                Console.ForegroundColor = ConsoleColor.Black;
                if (CheckWin(s))            {
                    Console.WriteLine(s + " win!!!");                
                }            
            }
             public static void PushXO(int i, int j, char s)
            { 
                titato[i, j] = s; 
            }
             public static void Main(string[] args)
            { 
                bool symbolX = true; 
                char s = 'x'; 
                int i = 0, j = 0; 
                do            { 
                    Console.WriteLine("TIC TAC TOE!"); 
                    PrintTicTacToe(s); 
                    if (symbolX == true)                {                    
                        Console.WriteLine("Ходит Х");
                        Console.WriteLine("Введите номер столбца а затем введите номер строки:"); 
                        s = 'x'; 
                        symbolX = false;  
                    } 
                    else                { 
                        Console.WriteLine("Ходит О");
                        Console.WriteLine("Введите номер столбца а затем введите номер строки:");
                        s = 'o';                    
                        symbolX = true; 
                    } 
                     i = int.Parse(Console.ReadLine()); 
    
                    j = int.Parse(Console.ReadLine());
     
                    PushXO(j, i, s);
     
                    //   Console.ReadLine();
     
                    PrintTicTacToe(s);
     
     
                } while (true);
     
            }

    Крестики-нолики

    Psilon, 14 Мая 2013

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

    +127

    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
    //top edge
                if (normal)
                    for (int i = y; i > 0; i--)
                        if (_map[x, i] == 0)
                            if ((i - 1) > minDist) { mnt.Corners[0] = new Point(x, i - 1 + minDist); break; }
                            else { normal = false; mnt.Height = -1; }
    
                //top-right edge
                if (normal)
                    for (int i = 0; ((x + i) < MAP_SIZE) & ((y - i) > 0); i++)
                        if (_map[x + i, y - i] == 0)
                            if (Math.Sqrt(2) * (MAP_SIZE - i) > minDist) { mnt.Corners[1] = new Point(x + i - 1 - minDist, y - i + 1 + minDist); break; }
                            else { normal = false; mnt.Height = -1; }
    
                //right edge
                if (normal)
                    for (int i = x; i < MAP_SIZE; i++)
                        if (_map[i, y] == 0)
                            if ((MAP_SIZE - i - 1) > minDist) { mnt.Corners[2] = new Point(i - 1 - minDist, y); break; }
                            else { normal = false; mnt.Height = -1; }
    
                //bottom-right edge
                if (normal)
                    for (int i = 0; ((x + i) < MAP_SIZE) & ((y + i) < MAP_SIZE); i++)
                        if (_map[x + i, y + i] == 0)
                            if (Math.Sqrt(2) * (MAP_SIZE - i) > minDist) { mnt.Corners[3] = new Point(x + i - 1 - minDist, y + i - 1 - minDist); break; }
                            else { normal = false; mnt.Height = -1; }
    
                //bottom edge
                if (normal)
                    for (int i = y; i > 0; i++)
                        if (_map[x, i] == 0)
                            if ((i - 1) > minDist) { mnt.Corners[4] = new Point(x, i - 1 - minDist); break; }
                            else { normal = false; mnt.Height = -1; }
    
                //bottom-left edge
                if (normal)
                    for (int i = 0; ((x - i) < MAP_SIZE) & ((y + i) > 0); i++)
                        if (_map[x - i, y + i] == 0)
                            if (Math.Sqrt(2) * (MAP_SIZE - i) > minDist) { mnt.Corners[5] = new Point(x - i + 1 + minDist, y + i - 1 - minDist); break; }
                            else { normal = false; mnt.Height = -1; }
    
                //left edge
                if (normal)
                    for (int i = x; i > 0; i--)
                        if (_map[i, y] == 0)
                            if ((i + 1) > minDist) { mnt.Corners[6] = new Point(i + 1 + minDist, y); break; }
                            else { normal = false; mnt.Height = -1; }
    
                //top-left edge
                if (normal)
                    for (int i = 0; ((x - i) > 0) & ((y - i) > 0); i++)
                        if (_map[x - i, y - i] == 0)
                            if (Math.Sqrt(2) * (MAP_SIZE - i) > minDist) { mnt.Corners[7] = new Point(x - i + 1 + minDist, y - i + 1 + minDist); break; }
                            else { normal = false; mnt.Height = -1; }

    Мне было лень думать. Очень лень.

    RaZeR, 11 Мая 2013

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

    +135

    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
    public bool IsSupportServerVersion()
        {
          if (this._connMaster.State == ConnectionState.Closed)
            this._connMaster.Open();
          if (int.Parse(((object) this._connMaster.ServerVersion.Split(new char[1]
          {
            '.'
          })[0]).ToString()) >= 9)
          {
            if (int.Parse(((object) this._connMaster.ServerVersion.Split(new char[1]
            {
              '.'
            })[0]).ToString()) <= 10)
              return true;
          }
          return false;
        }

    Проверка версии MSSQL. На фоне того, что писателями заявлена работа с 2005, смотрится особенно хорошо.

    croacker, 08 Мая 2013

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

    +136

    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
    // Было
    string postCode;
    if (person != null)
    {
      if (HasMedicalRecord(person) && person.Address != null)
      {
        CheckAddress(person.Address);
        if (person.Address.PostCode != null)
          postCode = person.Address.PostCode.ToString();
        else
          postCode = "UNKNOWN";
      }
    }
    // Стало
    string postCode = this.With(x => person)
        .If(x => HasMedicalRecord(x))]
        .With(x => x.Address)
        .Do(x => CheckAddress(x))
        .With(x => x.PostCode)
        .Return(x => x.ToString(), "UNKNOWN");

    "как можно использовать более “монадический” синтаксис в C# для того, чтобы __повысить удобочитаемость__ исходного кода"
    http://www.gotdotnet.ru/blogs/nesteruk/6975/

    Sh1tM4ker, 07 Мая 2013

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

    +133

    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
    //программист
            private void work7_Click(object sender, EventArgs e)
            {
                if ((player.CompLevel > 50) & (player.GamedevLevel > 20))
                {
                    work1.Enabled = true;
                    work2.Enabled = true;
                    work3.Enabled = true;
                    work4.Enabled = true;
                    work5.Enabled = true;
                    work6.Enabled = true;
                    work7.Enabled = false;
                    player.Salary = 20000;
                    player.Levels = 50;
                    player.HealthWork = 0;
                    Game_Update();
                }
                else MessageBox.Show("Ты еще плохо знаешь программирование и компьютер");
            }

    Оттуда ж.

    tirinox, 03 Мая 2013

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

    +135

    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
    string t = label1.Text;
    char[] bits = t.ToCharArray();
    int a1 = (Convert.ToInt16(bits[0]) - 48) + (Convert.ToInt16(bits[1]) - 48) + (Convert.ToInt16(bits[2]) - 48) + (Convert.ToInt16(bits[3]) - 48) + (Convert.ToInt16(bits[4] - 48));
                    char[] hemming = { '0', '0', bits[0], '0', bits[1], bits[2], bits[3], '0', bits[4] };
                    if (a1 == 1 || a1 == 2 || a1 == 4)
                    {
                        hemming[0] = '0';
                    }
                    else
                    { hemming[0] = '1'; }
                    int a2 = (Convert.ToInt16(hemming[2] - 48) + Convert.ToInt16(hemming[5] - 48) + Convert.ToInt16(hemming[6] - 48));
                    if (a2 == 1 || a2 == 2 || a2 == 4)
                    {
                        hemming[1] = '0';
                    }
                    else
                    { hemming[1] = '1'; }
                    int a3 = (Convert.ToInt16(hemming[4] - 48) + Convert.ToInt16(hemming[5] - 48) + Convert.ToInt16(hemming[6] - 48));
                    if (a3 == 1 || a3 == 2 || a3 == 4)
                    {
                        hemming[3] = '0';
                    }
                    else
                    { hemming[3] = '1'; }
                    if (hemming[7] == '1')
                    {
                        hemming[8] = '1';
                    }
                    else
                    { hemming[8] = '0'; }

    Реализация кода Хемминга (орфография и пунктуация сохранены)

    Psilon, 03 Мая 2013

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

    +102

    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
    if (
         !(this.Department.Length == 4 && 
                "0123456789".Contains(this.Department[0]) && 
                "0123456789".Contains(this.Department[1]) && 
                "0123456789".Contains(this.Department[2]) && 
                "0123456789".Contains(this.Department[3])) &&
         !(this.Department.Length == 4 && 
                "0123456789".Contains(this.Department[0]) && 
                "ABCDEFGHIJKLMNOPQRSTUVWXYZ".Contains(this.Department[1]) && 
                "ABCDEFGHIJKLMNOPQRSTUVWXYZ".Contains(this.Department[2]) && 
                "ABCDEFGHIJKLMNOPQRSTUVWXYZ".Contains(this.Department[3])) &&
         !(this.Department.Length == 5 && 
                "0123456789".Contains(this.Department[0]) && 
                "0123456789".Contains(this.Department[4]) && 
                "ABCDEFGHIJKLMNOPQRSTUVWXYZ".Contains(this.Department[1]) && 
                "ABCDEFGHIJKLMNOPQRSTUVWXYZ".Contains(this.Department[2]) && 
                "ABCDEFGHIJKLMNOPQRSTUVWXYZ".Contains(this.Department[3])))
         {
          return "error";
         }

    Он видимо не знал о существовании регулярных выражений

    NeoN, 02 Мая 2013

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

    +101

    1. 1
    2. 2
    3. 3
    4. 4
    if(searchParams == null)
    {
    	throw new NullReferenceException("параметры поиска = null" + searchParams.ToString());
    }

    Эдакий InnerException, чтоб верняково

    NeoN, 01 Мая 2013

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