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

    +129

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    public void UpdateSession()
            {
                this.RequestTypeId = this.RequestTypeId;
                this.ServiceId = this.ServiceId;
                this.Name = this.Name;
            }

    "Обновление" сессии. Взято из реального проекта.

    wader, 03 Мая 2011

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

    +113

    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
    public bool Read_XMl_File (XDocument Xml_Document, ref game_data Game_Data) { 
                bool Is_Success=false;          /* Captures this function's result */
    
                try { 
                    this.Xml_Data = (game_data)Game_Data;
    /*              Recursively read through entire XML Document */ 
                    Xml_Document.Root.RecursivelyProcess ( 
                        Process_Child_Element,
                        Process_Parent_Element_Open,
                        Process_Parent_Element_Close);
                    Is_Success = true;
                    }
    
                catch (Exception ex) { throw ex; }
    
                Game_Data = this.Xml_Data;    /* Pass the data back to Xml_Data */
                return Is_Success;
                }
     public static void RecursivelyProcess (
                    this XElement element,
                    Action<XElement, int> childAction,
                    Action<XElement, int> parentOpenAction,
                    Action<XElement, int> parentCloseAction) {  
                if (element == null) { throw new ArgumentNullException ("element"); } 
                element.RecursivelyProcess (0, childAction, parentOpenAction, parentCloseAction);  
                }  
    
     private static void RecursivelyProcess (  
                this XElement element,  
                int depth,  
                Action<XElement, int> childAction,  
                Action<XElement, int> parentOpenAction,  
                Action<XElement, int> parentCloseAction)  { 
     
                if (element == null)  { throw new ArgumentNullException ("element"); } 
                if (!element.HasElements) {         /* Reached the deepest child */
                    if (childAction != null) { childAction (element, depth); }  
                    }  
                else  {                             /* element has children */
                    if (parentOpenAction != null)  { parentOpenAction (element, depth); }  
                    depth++;  
                   
                    foreach (XElement child in element.Elements ())  {  
                        child.RecursivelyProcess ( depth,  childAction,  parentOpenAction,  parentCloseAction );  
                        }     
                    depth--;  
                    
                    if (parentCloseAction != null)  {  parentCloseAction (element, depth);  }
                    }  
                }
            }

    Avance, 29 Апреля 2011

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

    +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
    28. 28
    29. 29
    30. 30
    private void Gamexxx_Bolls_KeyDown(object sender, KeyEventArgs e)
    {
    OTCTeleText ttText;
    List TTList;
    TTList = new List();
    if (e.KeyValue == 13)
    {
    try
    {
    //Control ctrl = (Control)sender;
    ctrl = (Control)sender;
    String szName = ctrl.Name.Substring(16);
    int nOrderNumber = Convert.ToInt32(szName);
    int nNumber = 0;
    try
    {
    nNumber = Convert.ToInt32(ctrl.Text);
    }
    catch (Exception /*ex*/)
    {
    }
    
    .......
    
    }
    catch (Exception /*ex*/)
    {
    }
    }
    }

    Ярое использование трайкетча и чрезмерное внимание к женщинам лёгкого поведения ведут к освенциму.
    TryParse вместо тысячи слов
    Да, аве мне, аве!

    ursus, 28 Апреля 2011

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

    +121

    1. 1
    2. 2
    3. 3
    4. 4
    if (lvwUsers.SelectedItems[0].SubItems[1].Text != "" || 
                                lvwUsers.SelectedItems[0].SubItems[1].Text != string.Empty)
                            {
                                SecuritySettings.AuthenticationProtocol = ....

    wwwww, 28 Апреля 2011

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

    +120

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public void PauseCheck(int x)
    {
        for (int i = 0; i < (x / 10); i++)
        {
          Thread.Sleep(10);
        }
    }

    psina-from-ua, 27 Апреля 2011

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

    +108

    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(FileStream fs = new FileStream("имя файла", FileMode.CreateNew))
    {
      using(StreamWriter sw = new StreamWriter(fs))
      {
        sw.Write("Lloyd ");
        sw.Write("is ");
        sw.Write("cool ");
        sw.Write("guy. ");
        sw.Write(":)");
        sw.Flush();
      }
    }

    Взято здесь http://www.rsdn.ru/forum/dotnet/394039.flat.aspx
    Я не очень часто пишу на C#, но насколько я знаю, использование конструкции using предполагает, автоматическое очищение буфферов в конце блока кода.

    g00d, 27 Апреля 2011

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

    +124

    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
    private void TextBox_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.Key == Key.Space)
                {
                    TextBox box = sender as TextBox;
    
                    int start = box.SelectionStart;
                    int length = box.SelectionLength;
    
                    if (length == 0)
                    {
                        box.Text = box.Text.Insert(start + length, " ");
                        box.SelectionStart = start + 1;
                    }
                    else
                    {
                        string str1 = box.Text.Substring(0, start);
                        string str2 = box.Text.Substring(start + length);
    
                        box.Text = str1 + " " + str2;
                        box.SelectionStart = start + 1;
                    }
    
                    e.Handled = true;
                }
            }

    Отборный говнокод выращенный на территории Индии.
    Видимо им зарплату действительно за строчки кода платят.

    strato, 26 Апреля 2011

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

    +146

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    try
    {
        File.Delete(generatedFile);
    }
    catch { }

    И такое бывает...

    Mathematician, 26 Апреля 2011

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

    +119

    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
    private void Form1_Paint(object sender, PaintEventArgs e)
            {
                Graphics p=e.Graphics;
                p.DrawRectangle(Pens.Black, 100, 100, 120, 120);
                p.DrawLine(Pens.Black, 100, 100, 150, 80);
                p.DrawLine(Pens.Black, 220, 100, 270, 80);
                p.DrawLine(Pens.Black, 270, 80, 150, 80);
                p.DrawLine(Pens.Black, 220, 220, 270, 190);
                p.DrawLine(Pens.Black, 270, 190, 270, 80);
                p.DrawLine(Pens.Black, 140, 100, 140, 220);//Вертикальные линнии
                p.FillRectangle(Brushes.Beige, 101, 101, 39, 39);
                p.FillRectangle(Brushes.Brown, 101, 141, 39, 39);
                p.FillRectangle(Brushes.DarkBlue, 101, 181, 39, 39);
                p.FillRectangle(Brushes.ForestGreen, 141, 101, 39, 39);
                p.FillRectangle(Brushes.LightGreen, 181, 101, 39, 39);
                p.FillRectangle(Brushes.MediumTurquoise, 141, 141, 39, 39);
                p.FillRectangle(Brushes.OrangeRed, 181, 181, 39, 39);
                p.FillRectangle(Brushes.Orchid, 141, 181, 39, 39);
                p.FillRectangle(Brushes.Plum, 181, 141, 39, 39);
                p.DrawLine(Pens.Black, 180, 100, 180, 220);//Вертикальные  линнии
                p.DrawLine(Pens.Black, 100, 140, 220, 140);// Горихонтальные линнии
                p.DrawLine(Pens.Black, 100, 180, 220, 180);// Горихонтальные линнии
                p.DrawLine(Pens.Black, 140, 100, 190, 80);
                p.DrawLine(Pens.Black, 180, 100, 230, 80);
                p.DrawLine(Pens.Black, 220, 140, 270, 115);
                p.DrawLine(Pens.Black, 220, 180, 270, 155);
                p.DrawLine(Pens.Black, 121, 92, 239, 92);
                p.DrawLine(Pens.Black, 137, 86, 253, 86);
                p.DrawLine(Pens.Black, 239, 92, 239, 209);
                p.DrawLine(Pens.Black, 253, 86, 253, 200);
            }

    Рисуем одну грань кубика Рубика.

    http://www.cyberforum.ru/csharp-beginners/thread281606.html

    psina-from-ua, 23 Апреля 2011

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

    +120

    1. 1
    (class|struct|union)[\s\r\n(\w+)]*?(\w*)[\s\r\n]*?(:[\s\r\n(virtual)]*?\w+[\s\r\n]*?\w+(<\s*\w*\s*>)?([\s\r\n]*?,[\s\r\n(virtual)]*?\w+[\s\r\n]*?\w+(<\s*\w*\s*>)?)*?)?[\s\r\n]*?{[^{}]*(((?'open'{)[^{}]*)+((?'close-open'})[^{}]*)+)*(?(Open)(?!))[^{}]*}\s*?;

    Выделение из исходников именованных с++ классов. Глаза боятся, но вроде работает.

    m_gerz, 22 Апреля 2011

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