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

    +114

    1. 1
    EventTypeId = (int)Enum.Parse(typeof(AmazonMailingLogEventType), Enum.GetName(typeof(AmazonMailingLogEventType), AmazonMailingLogEventType.SendEmailError))

    вместо
    EventTypeId = (int)AmazonMailingLogEventType.SendEmail Error

    mozg_raka, 11 Апреля 2012

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

    +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
    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
    string result = Encoding.GetEncoding(CharSet).GetString(resultData);
                //       сам паттерн    \[\[\[\"([^"]*)
    
    
                String commonString = "";
                commonString += @"\";
                commonString += @"[";
                commonString += @"\";
                commonString += @"[";
                commonString += @"\";
                commonString += @"[";
                commonString += @"\";
                commonString += "\"";
                commonString += @"(";
                commonString += "[";
                commonString += "^";
                commonString += "\"";
                commonString += @"]";
                commonString += @"*";
                commonString += @")";
                String pattern = commonString;
    
                Regex reg = new Regex(pattern);
                var mathces = reg.Match(result);
                String stringResult = mathces.ToString().Replace("[[[\"", "");

    Сборка паттерна регулярки, скажите как можно такое покороче собрать

    AndrKn, 11 Апреля 2012

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

    +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
    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
    for (int Low = 0, Up = 8; (Low <= 72) & (Up <= 80); Low += 12, Up += 12)
                                    if ((i >= Low) & (i <= Up))
                                    {
                                        a = 0;
                                        for (int l = 0; l <= 13 * 3; l += 13)
                                        {
                                            if (labels[i + l].Text == "X")
                                            {
                                                a += 1;
                                                if ((l == 13 * 3) & (a != 4)) a = 0;
                                            }
                                            else a = 0;
                                        }
                                        if (a == 4)
                                        {
                                            if ((i != 8) & (i != 72))
                                            {
                                                if ((i == Low) | ((i >= 0) & (i <= 7)))
                                                    if (labels[i + 13 * 4].Text == "-")
                                                    {
                                                        labels[i + 13 * 4].Text = "O";
                                                        win = true;
                                                        goto End2;
                                                    }
                                                if ((i == Up) | ((i >= 73) & (i <= 80)))
                                                    if (labels[i - 13].Text == "-")
                                                    {
                                                        labels[i - 13].Text = "O";
                                                        win = true;
                                                        goto End2;
                                                    }
                                                if (i == Low)
                                                    if (labels[i + 13 * 4].Text == "-")
                                                    {
                                                        labels[i + 13 * 4].Text = "O";
                                                        win = true;
                                                        goto End2;
                                                    }
                                                if (i == Up)
                                                    if (labels[i - 13].Text == "-")
                                                    {
                                                        labels[i - 13].Text = "O";
                                                        win = true;
                                                        goto End2;
                                                    }
                                                if (((i >= 0) & (i <= 7)) | ((i >= 73) & (i <= 80)) | (i == Low) | (i == Up)) ;
                                                else
                                                {
                                                    if (labels[i + 13 * 4].Text == "O")
                                                        if (labels[i - 13].Text == "-")
                                                        {
                                                            labels[i - 13].Text = "O";
                                                            win = true;
                                                            goto End2;
                                                        }

    Полная версия: http://pastebin.com/gZFjYrtM

    P4R4, 10 Апреля 2012

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

    +158

    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
    private void OnLabelClick(object sender, EventArgs eventArgs)
            {
                    for (int End = 0; End < 1; End++)
                    {
                        if (((Label)sender).Text == "-")
                        {
                            ((Label)sender).Text = "X";
                        var labels = Controls.OfType<Label>().ToList();
                        for (int i = 0; i < labels.Count; i++)
                        {
                            int a = 0;
                            bool win = false;
                            if (labels[i].Text == "X")
                            {
                                for (int Low = 0, Up = 7; (Low <= 108) & (Up <= 115); Low += 12, Up += 12)
                                    if ((i >= Low) & (i <= Up))
                                    {
                                        a = 0;
                                        for (int l = 0; l < 5; l++)
                                            if (labels[i + l].Text == "X")
                                            {
                                                a += 1;
                                                if ((l == 4) & (a != 5)) a = 0;
                                            }
                                            else a = 0;
                                        if (a == 5) goto End;
                                    }
                                if (i <= 71)
                                {
                                    a = 0;
                                    for (int l = 0; l <= 12 * 4; l += 12)
                                        if (labels[i + l].Text == "X")
                                        {
                                            a += 1;
                                            if ((l == 12 * 5) & (a != 5)) a = 0;
                                        }
                                        else a = 0;
                                    if (a == 5) goto End;
                                }
                                for (int Low = 0, Up = 7; (Low <= 60) & (Up <= 67); Low += 12, Up += 12)
                                    if ((i >= Low) & (i <= Up))
                                    {
                                        a = 0;
                                        for (int l = 0; l <= 13 * 4; l += 13)
                                            if (labels[i + l].Text == "X")
                                            {
                                                a += 1;
                                                if ((l == 13 * 5) & (a != 5)) a = 0;
                                            }
                                            else a = 0;
                                        if (a == 5) goto End;
                                    }
                                for (int Low = 4, Up = 11; (Low <= 64) & (Up <= 71); Low += 12, Up += 12)
                                    if ((i >= Low) & (i <= Up))
                                    {
                                        a = 0;
                                        for (int l = 0; l <= 11 * 4; l += 11)
                                            if (labels[i + l].Text == "X")
                                            {
                                                a += 1;
                                                if ((l == 11 * 5) & (a != 5)) a = 0;
                                            }
                                            else a = 0;
                                        if (a == 5) goto End;
                                    }
                            }
                        End: if (a == 5)
                            {
                                MessageBox.Show("You Win!");
                                a = 0;
                                EndAll = true;
                                goto EndAll;
                            }
                        }

    (C) http://gordon.ucoz.com/publ
    Автор Я, сайт мой.
    Это не полный код!

    Gordon, 09 Апреля 2012

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

    +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
    using System;
    
    namespace IPGuard
    {
    	class Program
    	{
    		public static void Main(string[] args)
    		{
    			System.Net.IPAddress IPAdress = null;
    			System.Net.NetworkInformation.Ping Ping = null;
    			for (int IP1 = 1; IP1 < 255; IP1++)
    			{
    				for (int IP2 = 0; IP2 < 255; IP2++) 
    				{
    					for (int IP3 = 0; IP3 < 255; IP3++) 
    					{
    						for (int IP4 = 0; IP4 < 255; IP4++) 
    						{
    							IPAdress = System.Net.IPAddress.Parse(Convert.ToString(IP1) + "." + Convert.ToString(IP2) + "." + Convert.ToString(IP3) + "." + Convert.ToString(IP4));
    							Ping = new System.Net.NetworkInformation.Ping();
    							if (Ping.Send(IPAdress).Status == System.Net.NetworkInformation.IPStatus.Success) 
    							{
    								Console.WriteLine(IPAdress);
    							} 
    						}
    					}
    				}
    			}
    		}
    	}
    }

    Программа для поиска всех доступных IP адрессов.

    KusokGovna, 07 Апреля 2012

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

    +117

    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
    private void cmd_Click(object sender, MouseEventArgs e)
        {
            for (int y = 0; y < matrixHeight; y++)
            {
                for (int x = 0; x < matrixWidth; x++)
                {
                    if (cmd[x, y].GetHashCode() == sender.GetHashCode())
                    {
                        //your code here
                    }
                }
            }
        }

    Таким волшебным способом реализован единый метод обработки кликов для двумерного массива кнопок...

    vistefan, 06 Апреля 2012

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

    +124

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    if (!string.IsNullOrEmpty(ReadTextFile("BrandsSitemap.xml")))
    
    ...
    public string ReadTextFile(string fileName)
            {
                string fullPath = Server.MapPath("~/") + fileName;
                StreamReader sr = new StreamReader(fullPath);
                return sr.ReadToEnd();
            }

    Коммерческий проект.
    Проверка файла на существование. Файлы бывают по несколько метров))

    sergfreest, 06 Апреля 2012

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

    +116

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    protected void chxPeriodCostDeviationGreater_CheckedChanged(object sender, EventArgs e)
            {
                foreach (Pair lstPair in lstPairs)
                {
                    if (lstPair.First.Equals(sender))
                    {
                        (lstPair.Second as TextBox).Enabled = (lstPair.First as CheckBox).Checked;
                        return;
                    }
                }
            }

    задаем видимость контролов :)

    _vinka, 05 Апреля 2012

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

    +110

    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
    public class CatalogCache : IDIsposable
    {
        public void Dispose()
        {
            if (_loadThread != null)
            {
                if (_loadThread.IsAlive)
                    _loadThread.Abort();
            }
    
            if (_updateThread != null)
            {
                if (_updateThread.IsAlive)
                    _updateThread.Abort();
            }
    }

    abatishchev, 05 Апреля 2012

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

    +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
    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
    switch (count)
    {
    	case 2:
    		return Tuple.Create(col[1]);
    	case 3:
    		return Tuple.Create(col[1], col[2]);
    	case 4:
    		return Tuple.Create(col[1], col[2], col[3]);
    	case 5:
    		return Tuple.Create(col[1], col[2], col[3], col[4]);
    	case 6:
    		return Tuple.Create(col[1], col[2], col[3], col[4], col[5], col[6]);
    	case 8:
    		return Tuple.Create(col[1], col[2], col[3], col[4], col[5], col[6], col[7]);
    	case 9:
    		return Tuple.Create(col[1], col[2], col[3], col[4], col[5], col[6], col[7], col[7]);
    	case 10:
    		return Tuple.Create(col[1], col[2], col[3], col[4], col[5], col[6], col[7], Tuple.Create(col[8]));
    	case 11:
    		return Tuple.Create(col[1], col[2], col[3], col[4], col[5], col[6], col[7], Tuple.Create(col[8], col[9]));
    	case 12:
    		return Tuple.Create(col[1], col[2], col[3], col[4], col[5], col[6], col[7], Tuple.Create(col[8], col[9], col[10]));
    	case 13:
    		return Tuple.Create(col[1], col[2], col[3], col[4], col[5], col[6], col[7], Tuple.Create(col[8], col[9], col[10], col[11]));
    	case 14:
    		return Tuple.Create(col[1], col[2], col[3], col[4], col[5], col[6], col[7], Tuple.Create(col[8], col[9], col[10], col[11], col[12]));
    	default:
    		throw new ArgumentOutOfRangeException("count", count, "Can't convert array to tuple.");
    }

    a553r7fa1L3d, 05 Апреля 2012

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