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

    +118

    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
    private Excel._Application _excel;
    ...
    private void RefreshFormulas(FormulaRefreshOption formulaRefreshOption, object objectToRefresh)
    		{
    			//Где-то в дебрях километрового метода бросилось в глаза
                            ...
    			try
    			{
    				Excel.Range intersection = selection, selection2 = selection;
    				while (selection2 != null)
    				{
    					intersection = _excel.Intersect(selection2, selection2.Dependents,
    						Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
    						 Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
    						  Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
    						   Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
    
    
    					System.Windows.Forms.Application.DoEvents();
    					excelUtilities.RecalculateRangeInstance(true, intersection/*_excel.Selection as Excel.Range*/);
    					selection2 = intersection;
    				}
    
    			}
    			catch (Exception) { /*ignore the exception because .Dependents will throw an exception if there aren't any dependents*/}
                            ...
    		}

    fade, 04 Января 2012

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

    +122

    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
    while (!requestedTermination)
    {
        // ...
        // тут  130 строк кода...
        // ...
    
        if (requestedTermination)
        {
            break;
        }
        else
        {
            // to prevent excess CPU usage
            Thread.Sleep(100);
        }
    }

    requestedTermination - Property, изменяемое другим потоком

    Мораль: не пишите длинные циклы - к концу цикла забудете, какое у него было условие завершения.

    burdakovd, 16 Декабря 2011

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

    +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
    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
    /// <summary>
            /// Abs function
            /// </summary>
            private static object Abs(List<Expression> p)
            {
                return Math.Abs(p[0]);
            }
    
            /// <summary>
            /// Acos function
            /// </summary>
            private static object Acos(List<Expression> p)
            {
                return Math.Acos(p[0]);
            }
    
            /// <summary>
            /// Asin function
            /// </summary>
            private static object Asin(List<Expression> p)
            {
                return Math.Asin(p[0]);
            }
    
            /// <summary>
            /// Atan function
            /// </summary>
            private static object Atan(List<Expression> p)
            {
                return Math.Atan(p[0]);
            }
    
            /// <summary>
            /// Atan2 function
            /// </summary>
            private static object Atan2(List<Expression> p)
            {
                return Math.Atan2(p[0], p[1]);
            }

    Кусок кода от "Капитана Очевидность"

    govnokoder_, 15 Декабря 2011

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

    +146

    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
    public ActionResult RenderDesigner()
    {
        // Get the received text
        var received = string.Empty;
        using(var reader = new StreamReader(Request.InputStream))
        {
            received = reader.ReadToEnd();
        }
    
        // Possible texts received
        var xml = "";
        var id = "";
        var moveId = "";
        int distance = 0;
        
        // Get all string from received
        var keys = received.Split('&');
        for (var i = 0; i < keys.Length; i++)
        {
            // XML
            if(keys[i].StartsWith("xml="))
            {
                xml = Server.UrlDecode(keys[i].Split('=')[1]);
            }
    
            // ID
            else if (keys[i].StartsWith("id="))
            {
                id = keys[i].Split('=')[1];
            }
            // Position
            else if (keys[i].StartsWith("distance="))
            {
                distance = int.Parse(keys[i].Split('=')[1]);
            }
    
            // Move ID
            else if (keys[i].StartsWith("moveId="))
            {
                moveId = keys[i].Split('=')[1];
            }
        }
    }

    разбор параметров POST запроса в стиле MVC

    Eugene, 15 Декабря 2011

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

    +122

    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
    Controller.cs
    
    	public ActionResult SomeAction()
    	{
    		return View("My message");
    	}
    
    SomeAction.cshtml
    
    @{
    	Layout = null;
    }
    @Html.Raw(string.Format("{0}", Model.ToString()))

    Да, это ASP.Net MVC

    medved123, 14 Декабря 2011

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

    +980

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    private string doubleToString(double v)
    {
        if (v < 0)
            return "-" + (-(int)v).ToString() + "." + (-(v - (int)v) * 10000000).ToString("0000000.");
        return ((int)v).ToString() + "." + ((v - (int)v) * 10000000).ToString("0000000.");
    }

    Превращаем double в строку. Разделитель - надо точку, а то "блин, он ставит запятую, SQL-сервер потом это не понимает" (с)

    Meowth, 14 Декабря 2011

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

    +120

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    for (; itemList.Parent != null; {
            Item parent;
            itemList = parent.Parent;
        }
    )
    {
        parent = itemList.Parent.Parent.Parent;
        list.Add((object) parent);
    }

    Crazzy, 14 Декабря 2011

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

    +118

    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
    private void увеличитьToolStripMenuItem_Click(object sender, EventArgs e)
            {
                panel1.Height = panel1.Height * 2;
                panel1.Width = panel1.Width * 2;
    
                graph = panel1.CreateGraphics();
                graph.Clear(Color.White);
                if (Setka)
                {
                    DrawSetka();
                }
                foreach (Fig f in figures)
                {
                    f.Masstab = f.Masstab * 2;
                    f.DrawFigure(graph);
                }
                resizeScrollBars();
                
    
            }

    Обратите внимание на название метода

    baddotnet, 09 Декабря 2011

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

    +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
    // Getting first account data and binding it to control
                    List<string> cardList = new List<string>();
                    List<string> permissionList = new List<string>();
                    string x1 = "";
                    string x2 = "";
                    string x3 = "";
                    string x4 = "";
                    string x6 = "";
                    string x7 = "";
                    string x8 = "";
                    try
                    {
                        x8 = getCardNumberByAccountNumber(CustAcc1.Text);
                    }
                    catch { }
                    GetAllCustomerAccountValue(de_ca1, ref x1, ref x2, ref x3, ref x4, ref cardList, ref permissionList, ref x6, ref x7, ref x8); //, ref x2, ref x3, ref x4, ref cardList, ref x5, ref x6, ref x7, ref x8);
                    FormCustomerAccount1.accountNum = x1;
                    FormCustomerAccount1.fullName = x2;
                    FormCustomerAccount1.streetBuild = x3;
                    FormCustomerAccount1.postalCode = x4;
                    FormCustomerAccount1.creditNote = x6;
                    FormCustomerAccount1.accountBalance = x7;
                    FormCustomerAccount1.cards = cardList;
                    FormCustomerAccount1.permissions = permissionList;

    (

    ellk, 08 Декабря 2011

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

    +120

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    // LockDepth IS enum type!
    if(LockDepth == DepthType.Infinity)
    	_depthElement.InnerText = this.__lockDepth.ToString();
    else
    	_depthElement.InnerText = (string) System.Enum.Parse(LockDepth.GetType(), LockDepth.ToString(), true);

    I got exception on line 5. The LockDepth is enum :)

    bugotrep, 06 Декабря 2011

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