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

    +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
    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
    if (command == "help") ShowHelp();
                else if (command == "") Error(1);
                else
                {
                    string[] pcmd = command.Split(' ');
                    string[] args = { "0,0", "0,0" };
                    string argv = "Black";
                    if (pcmd[0] != "setColor" &&
                        pcmd[0] != "save" &&
                        pcmd[0] != "fill" &&
                        pcmd[0] != "saveCMD" &&
                        pcmd[0] != "close" &&
                        pcmd[0] != "if" &&
                        pcmd[0] != "from" &&
                        pcmd[0] != "setVar" &&
                        pcmd[0] != "getVar" &&
                        pcmd[0] != "setRGB" &&
                        pcmd[0] != "fillFRGB" &&
                        pcmd[0] != "fillRGB" &&
                        pcmd[0] != "setPenSize" &&
                        pcmd[0] != "fillF" &&
                        pcmd[1] != "#?") args = pcmd[1].Split('|');
                    else if (pcmd[0] == "setVar") argv = pcmd[1] + " " + pcmd[3];
                    else if (pcmd[1] == "#?")
                    {
                        Help4command(pcmd[0]);
                        return;
                    }
                    else argv = pcmd[1];
                    switch (pcmd[0])
                    {
                        case "save":
                            try { bmp.Save(argv + "\\" + Name + ".png",ImageFormat.Png); }
                            catch { Error(2); }
                            break;
                        case "line":
                            {
                                string[] xy0 = args[0].Split(',');
                                string[] xy1 = args[1].Split(',');
                                int x0 = 0, y0 = 0, x1 = 0, y1 = 0;
                                if (xy0[0] == "w" || xy0[0] == "W") x0 = W;
                                if (xy0[1] == "h" || xy0[1] == "H") y0 = H;
                                if (xy1[0] == "w" || xy1[0] == "W") x1 = W;
                                if (xy1[1] == "h" || xy1[1] == "H") y1 = H;
                                if (VL.isExistVar(xy0[0])) x0 = int.Parse(VL.Get(xy0[0]));
                                if (VL.isExistVar(xy0[1])) y0 = int.Parse(VL.Get(xy0[1]));
                                if (VL.isExistVar(xy1[0])) x1 = int.Parse(VL.Get(xy1[0]));
                                if (VL.isExistVar(xy1[1])) y1 = int.Parse(VL.Get(xy1[1]));
                                try
                                {
                                    x0 = int.Parse(xy0[0]);
                                    y0 = int.Parse(xy0[1]);
                                    x1 = int.Parse(xy1[0]);
                                    y1 = int.Parse(xy1[1]);
                                }
                                finally { }
                                graph.DrawLine(new Pen(usesCol, penSize), new Point(x0, y0), new Point(x1, y1));
                            }
                            break;
                        case "rect":
                            {
                                if (fiilF == false)
                                {
                                    string[] xy0 = args[0].Split(',');
                                    string[] xy1 = args[1].Split(',');
                                    int x0 = 0, y0 = 0, x1 = 0, y1 = 0;
                                    if (xy0[0] == "w" || xy0[0] == "W") x0 = W;
                                    if (xy0[1] == "h" || xy0[1] == "H") y0 = H;
                                    if (xy1[0] == "w" || xy1[0] == "W") x1 = W;
                                    if (xy1[1] == "h" || xy1[1] == "H") y1 = H;
                                    if (VL.isExistVar(xy0[0])) x0 = int.Parse(VL.Get(xy0[0]));
                                    if (VL.isExistVar(xy0[1])) y0 = int.Parse(VL.Get(xy0[1]));
                                    if (VL.isExistVar(xy1[0])) x1 = int.Parse(VL.Get(xy1[0]));
                                    if (VL.isExistVar(xy1[1])) y1 = int.Parse(VL.Get(xy1[1]));
                                   //еще +100500 строк говнокода

    Только что копался в старых проектах и наткнулся на это. Это была попытка сделать что-то вреде ЯП для рисования, своево рода черепашья графика, но со своими свистелками и сами знаете чем.

    psina-from-ua, 05 Мая 2011

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

    +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
    public bool SelectUserGroup(string UserName,string GroupName)
    {
        try
        {
            return true;
        }
        catch
        {
            return false;
        }
    }
    
    public KUser GetUserByKey(Guid Key)
    {
        try
        {
            return new KUser();
        }
        catch
        {
            return new KUser();
        }
    }

    Особая защита от исключительных ситуаций. Взято из реального проекта.

    Zergatul, 05 Мая 2011

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

    +122

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    private bool validDir(DirectoryInfo dir)
    {
    	return dir.Attributes == FileAttributes.Directory &&
    	dir.Attributes != FileAttributes.Hidden &&
    	dir.Attributes != FileAttributes.NotContentIndexed &&
    	dir.Name != "Windows";
    }

    GoodTalkBot, 04 Мая 2011

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

    +112

    1. 1
    2. 2
    3. 3
    4. 4
    foreach (int i in new int[] {1, 2, 3, 4, 5}) 
    {
         //Какие-то действия
    }

    Правильный for в C#
    http://2lx.ru/2010/03/pravilnyj-for-v-c/

    zheka, 04 Мая 2011

    Комментарии (22)
  5. 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)
  6. 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)
  7. 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)
  8. 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)
  9. 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)
  10. 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)