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

    +120

    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
    /// <summary>
    /// Calculates and returns a hashcode based on this user's
    /// MarketName and default units. The hashcode should be
    /// unique for each different combination of MarketName and 
    /// units.
    /// </summary>
    /// <returns>An int that may be positive or negative.</returns>
    public override int GetHashCode()
    {
    // A function like this raises innumerable questions.  Why did they over ride the 
    // hash code function?  Why did they use an attribute that is not certain to be unique?
    // why did they not use the one that is going to be unique?  Why did they not cvheck to 
    // see if the thing they were hasing was not null?  When did my life go so far off the rails
    // that I have to deal with code like this?  How many places call this code? Why did they not 
    // include any meaningful comments? Why does it suddenly start breaking after the 3.5 upgrade?
    // in an effort to avoid thinking about those questions, I've justy changed the has to use the 
    // unique user id instead of the retarded defaultuserunits hash.
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    sb.Append(this.MarketName);
    if (this.DefaultUserUnits != null)
    {
      sb.Append(Utility.StringUtility.GetJSObjectLiteral(this.DefaultUserUnits));
    }
    else
    {
      sb.Append(Utility.StringUtility.GetJSObjectLiteral(this.ID));
    }
      return sb.ToString().GetHashCode();
    }

    aprishchepov, 19 Ноября 2011

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

    +124

    1. 1
    _videoNum = (byte) (videoNum==0?videoNum:0);

    попалось сегодня в исходниках рабочего проекта

    _vinka, 18 Ноября 2011

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

    +121

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    public class MainSetting
      {
        // ...
        public void Load(out MainSetting objectToDeserialise) {...}
        // ...
      }

    Использвоание: _mainSetting.Load(out _mainSetting);

    ziaw, 15 Ноября 2011

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

    +123

    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
    static public int MeasureDisplayStringWidth(Graphics graphics, string text,
                                                Font font)
    {
        const int width = 32;
    
        System.Drawing.Bitmap   bitmap = new System.Drawing.Bitmap (width, 1, 
                                                                    graphics);
        System.Drawing.SizeF    size   = graphics.MeasureString (text, font);
        System.Drawing.Graphics anagra = System.Drawing.Graphics.FromImage(bitmap);
    
        int measured_width = (int) size.Width;
    
        if (anagra != null)
        {
            anagra.Clear (Color.White);
            anagra.DrawString (text+"|", font, Brushes.Black,
                               width - measured_width, -font.Height / 2);
    
            for (int i = width-1; i >= 0; i--)
            {
                measured_width--;
                if (bitmap.GetPixel (i, 0).R != 255)    // found a non-white pixel ?
    
                    break;
            }
        }
    
        return measured_width;
    }

    Ищем размер нарисованной строки. Не моё. Нашел на codeproject.
    (Вместо MeasureCharacterRanges)

    rammara, 14 Ноября 2011

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

    +131

    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
    string[] strArray1 = new string[6];
              string[] strArray2 = strArray1;
              int index1 = 0;
              DateTime now = DateTime.Now;
              string str1 = now.Month.ToString();
              strArray2[index1] = str1;
              string[] strArray3 = strArray1;
              int index2 = 1;
              now = DateTime.Now;
              string str2 = now.Day.ToString();
              strArray3[index2] = str2;
              string[] strArray4 = strArray1;
              int index3 = 2;
              now = DateTime.Now;
              string str3 = now.Year.ToString();
              strArray4[index3] = str3;
              string[] strArray5 = strArray1;
              int index4 = 3;
              now = DateTime.Now;
              string str4 = now.Hour.ToString();
              strArray5[index4] = str4;
              string[] strArray6 = strArray1;
              int index5 = 4;
              now = DateTime.Now;
              string str5 = now.Minute.ToString();
              strArray6[index5] = str5;
              string[] strArray7 = strArray1;
              int index6 = 5;
              now = DateTime.Now;
              string str6 = now.Second.ToString();
              strArray7[index6] = str6;
              Program.zipName = string.Concat(strArray1);

    jabacrack, 13 Ноября 2011

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

    +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
    public static string FristChar(this string input)
        {
            if (!string.IsNullOrEmpty(input))
            {
                if (input.Length >= 1)
                {
                    return input.Substring(0, 1);
                }
                else
                {
                    return input;
                }
            }
            else
            {
                return null;
            }
        }

    http://www.extensionmethod.net/Details.aspx?ID=170

    Author: Mehrdad Ghasemi

    Killster, 13 Ноября 2011

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

    +122

    1. 1
    2. 2
    if (!0.Equals(callResult.ValueOf("@retValue"))) // оба инт'ы
         ...

    Мы не ищем легких путей сравнения.

    fr0mrus, 11 Ноября 2011

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

    +121

    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
    private void textBox1_TextChanged(object sender, EventArgs e)
    {
    	if ((textBox1.Text + textBox2.Text).Length + 1 > 255)
    	{
    		textBox1.BackColor = Color.LightPink;
    		textBox2.BackColor = Color.LightPink;
    	}
    	else
    	{
    		textBox1.BackColor = Color.White;
    		textBox2.BackColor = Color.White;
    	}
    
    	if ((textBox3.Text + textBox6.Text).Length + 1 > 255)
    	{
    		textBox3.BackColor = Color.LightPink;
    		textBox6.BackColor = Color.LightPink;
    	}
    	else
    	{
    		textBox3.BackColor = Color.White;
    		textBox6.BackColor = Color.White;
    	}
    }
    
    private void bntSave_Click(object sender, EventArgs e)
    {
    	if (textBox1.BackColor == Color.LightPink)
    	{
    		MessageBox.Show("Длинна полей От и Адрес в сумме не должна превышать 255");
    		return;
    	}
    	if (textBox3.BackColor == Color.LightPink)
    	{
    		MessageBox.Show("Длинна полей Кому и Адрес в сумме не должна превышать 255");
    		return;
    	}
    
    	Properties.Settings.Default.Save();
    	Navigator.Navigate(new ConfigMenuPage());
    }

    ТЗ: "Суммарная длина полей X и Y не должна превышать 255 символов"
    Решение шедеврально как по вычислению длинны суммы строк, так и по цветовой идентификации :)

    ddv_demon, 10 Ноября 2011

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

    +116

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    IGridCell IGridControl.this[int columnIndex, int rowIndex]
            {
                get { return Cells.Single(c => c.OwningRow.Index == rowIndex && c.OwningColumn.Index == columnIndex); }
                set
                {
                    cells.Remove(cells.Single(c => c.OwningRow.Index == rowIndex && c.OwningColumn.Index == columnIndex));
                    cells.Add(value);
                }
            }

    вот такие вот индексаторы

    Ccik, 10 Ноября 2011

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

    +120

    1. 1
    if (ViewData["partialViewName"].ToString() == "" ||  ViewData["partialViewName"] == null)

    кратко и лаконично

    sergfreest, 09 Ноября 2011

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