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

    +136

    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
    private BusinessSocialProfile GetSocialProfileLink(string searchProvider, string searchKey)
    {
    	var link = new BusinessSocialProfile { Name = searchProvider, Url = "#" };
    	
    	if (searchProvider.Contains("city", StringComparison.InvariantCultureIgnoreCase))
    	{
    		link.Url = cityLink;
    		link.Logo = "/citysearch.png";
    		link.ImageStyle = "margin-top:-8px";
    	}
    	else if (searchProvider.Contains("google", StringComparison.InvariantCultureIgnoreCase))
    	{
    		link.Url = googleLink;
    		link.Logo = "/google.png";
    	}
    	else if (searchProvider.Contains("yelp", StringComparison.InvariantCultureIgnoreCase))
    	{
    		link.Url = yelpLink;
    		link.Logo = "/yelp.png";
    		link.ImageStyle = "margin-top:-8px";
    	}
    	else if (searchProvider.Contains("manta", StringComparison.InvariantCultureIgnoreCase))
    	{
    		link.Url = mantaLink;
    		link.Logo = "/manta.png";
    	}
    	else if (searchProvider.Contains("patch", StringComparison.InvariantCultureIgnoreCase))
    	{
    		link.Url = patchLink;
    		link.Logo = "/patch.png";
    	}
    	else
    	{
    		link.Url = "#";
    		link.Logo = string.Empty;
    		link.Name = string.Empty;
    	}
    
    	return link;
    }

    уже до боли известный девелопер ;) а для чего еще нужна бизнесс-логика...?

    mangyst, 16 Ноября 2012

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

    +136

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    for (var attempt = 0; attempt < 3; attempt++)
    {
        var result = (from neighborhood in this.DataContext.Neighborhoods
            join city in this.DataContext.Cities on neighborhood.CityId equals city.Id
            where !string.IsNullOrEmpty(neighborhood.Latitude) && (neighborhood.Id <= 31028 || attempt == 2) &&
            (attempt == 0 && !string.IsNullOrEmpty(location.city) ? (city.Name.Equals(location.city, StringComparison.InvariantCultureIgnoreCase)) : true)
        select new...).ToList();
    }

    просто linq, просто where;) От создателя xml-парсера (http://govnokod.ru/11870), обработки postback-запросов (http://govnokod.ru/10313), "обычного switch-а" (http://govnokod.ru/10448, http://govnokod.ru/10474), а еще конкатинации sql строк без параметров (но там слишком много, поэтому не выложу(:)

    mangyst, 13 Ноября 2012

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

    +134

    1. 1
    2. 2
    3. 3
    4. 4
    for (int i = X; i <= (X + 1); i++)
        {
            for (int j = Y; j <= (Y + 1); j++)
            {

    Crazy_penguin, 08 Ноября 2012

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

    +135

    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
    int index = 0;
            this.item[index].SetDefaults("Mining Helmet");
            index++;
            this.item[index].SetDefaults("Piggy Bank");
            index++;
            this.item[index].SetDefaults("Iron Anvil");
            index++;
            this.item[index].SetDefaults("Copper Pickaxe");
            index++;
            this.item[index].SetDefaults("Copper Axe");
            index++;
            this.item[index].SetDefaults("Torch");
            index++;
            this.item[index].SetDefaults("Lesser Healing Potion");
            index++;
            ...

    Crazy_penguin, 08 Ноября 2012

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

    +111

    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
    // todo
    /// <summary>
    /// Генерация пароля из GUID
    /// </summary>
    /// <param name="guid">GUID</param>
    /// <returns>пароль</returns>
    public string PasswordByGuid(string guid)
    {
        return guid[33].ToString()
            + guid[28].ToString()
            + guid[2].ToString()
            + guid[10].ToString()
            + guid[21].ToString()
            + guid[15].ToString();
    }

    Коммерческий проект :)

    ddv_demon, 08 Ноября 2012

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

    +141

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    private void button1_Click(object sender, EventArgs q)
            {
                int a, b, c, d, e, f, j, h, i;
                double w, r, t, y, u, o, p, s, g;
                double w1, r1, t1, y1, u1, o1, p1, s1, g1;
                double w2, r2, t2, y2, u2, o2, p2, s2, g2;
                for (a = 0; a < 1000;a++)
                {
                    for (b = 0; b < 1000; b++)
                    {
                        for (c = 0; c < 1000; c++)
                        {
                            for (d = 0; d < 1000; d++)
                            {
                                for (e = 0; e < 1000; e++)
                                {
                                    for (f = 0; f < 1000; f++)
                                    {
                                        for (j = 0; j < 1000; j++)
                                        {
                                            for (h = 0; h < 1000; h++)
                                            {
                                                for (i = 0; i < 1000; i++)
                                                {
                                                    if(a!=b && a!=c && a!=d && a!=e && a!=f && a!=j && a!=h && a!=i)
                                                    {
                                                        if (b != a && b != c && b != d && b != e && b != f && b != j && b != h && b != i)
                                                        {
                                                            if (c != b && c != a && c != d && c != e && c != f && c != j && c != h && c != i)
                                                            {
                                                                if (d != b && d != c && d != a && d != e && d != f && d != j && d != h && d != i)
                                                                {
                                                                    if (e != b && e != c && e != d && e != a && e != f && e != j && e != h && e != i)
                                                                    {
                                                                        if (f != b && f != c && f != d && f != e && f != a && f != j && f != h && f != i)
                                                                        {
                                                                            if (j != b && j != c && j != d && j != e && j != f && j != a && j != h && j != i)
                                                                            {
                                                                                if (h != b && h != c && h != d && h != e && h != f && h != j && h != a && h != i)
                                                                                {
                                                                                    if (i != b && i != c && i != d && i != e && i != f && i != j && i != h && i != a)
                                                                                    {
                                                                                        if (a + b + c == d + e + f)
                                                                                        {
                                                                                            if (a + b + c ==j + h + i)
                                                                                            {
    w = a + b;
    w1 = Math.Sqrt(w);
    w2=Math.Round(w1,0);
    if(w2*w2==w)
    {
    r = a + c;
    r1 = Math.Sqrt(r);
    r2=Math.Round(r1,0);
    if(r2*r2==r)
    {
    t=b + c;
    t1 = Math.Sqrt(t);
    t2=Math.Round(t1,0);
    if(t2*t2==t)
    {
    y = d + e;
    y1 = Math.Sqrt(y);
    y2=Math.Round(y1,0);
    if(y2*y2==y)
    {
    u = d + f;
    u1 = Math.Sqrt(u);
    u2=Math.Round(u1,0);
    if(u2*u2==u)
    {
    o = f + e;
    o1 = Math.Sqrt(o);
    o2=Math.Round(o1,0);
    if(o2*o2==o)
    {
    p = j + h;
    p1 = Math.Sqrt(p);
    p2=Math.Round(p1,0);
    if(p2*p2==p)
    {
    s = j + i;
    s1 = Math.Sqrt(s);
    s2=Math.Round(s1,0);
    if(s2*s2==s)
    {
    g = h + i;
    g1 = Math.Sqrt(g);
    g2=Math.Round(g1,0);
    if (g2 * g2 == g)
    {
     
        richTextBox1.Text += "первый ряд " + a + " " + b + " " + c + " второй ряд " + d + " " + e + " " + f + " третий ряд " + j + " " + h + " " + i;
    }
    else
    {
        richTextBox1.Text += "Нету такого";
    }
    }
    ... Много заказывающих скобок от всех условий и циклов выше

    Авторское описание "её суть в том, чтобы расчитать матрицу 3х3, где каждый элемент будет разным целым числом...при этом первый плюс второй должен быть полный квадрат, второй плюс третий тоже и первый плюс третий аналогично....это для первой строки...и так для двух других...а так же сумма элементов строки должны быть одинаковыми...т.е. a+b+c=d+e+f=j+h+i..."

    Psilon, 30 Октября 2012

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

    +136

    1. 1
    2. 2
    3. 3
    4. 4
    revision = String.Format("{0}{1:d2}{2:d2}",
    				DateTime.Now.Year.ToString().Substring(2),
    				DateTime.Today.Month,
    				DateTime.Today.Day);

    видно автор хотел сделать
    revision = DateTime.Today.ToString("yyMMdd");

    http://www.codeproject.com/Articles/272551/Custom-Assembly-Versioning-with-VS-2010-and-MSBUIL

    graph_di5, 28 Октября 2012

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

    +137

    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
    static /*public*/ string GenerateRandomJpegName()
            {
                return GenerateRandomString() + ".jpg";
            }
     
            static string GenerateRandomString()
            {
                bool UseSigns = true;
                bool UseUpperLetters = true;
                bool UseLetters = true;
                int Length;
            NewLabel:
                try
                {
                    Length = new Random(DateTime.Now.Millisecond - DateTime.Now.Second + new Random(DateTime.Now.Millisecond).Next(0, 100) / new Random(DateTime.Now.Millisecond - DateTime.Now.Second).Next(0, 10)).Next(0, 100);
                }
                catch { goto NewLabel; }
                string result = "C:/";
                try
                {
                    int Seed = 0;
                    char[] letters = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
                    char[] signs = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
                    List<char> keyWords = new List<char>();
                    List<char> upperLetters = new List<char>();
                    foreach (char c in letters)
                        upperLetters.Add(Convert.ToChar(c.ToString().ToUpper()));
                    if (UseLetters)
                        foreach (char c in letters)
                            keyWords.Add(c);
                    if (UseSigns)
                        foreach (char c in signs)
                            keyWords.Add(c);
                    if (UseUpperLetters)
                        foreach (char c in upperLetters)
                            keyWords.Add(c);
                    int MaxValue = keyWords.Count;
                    for (int i = 0; i <= Length; i++)
                    {
                        try
                        {
                            Random mainrand = new Random(Seed);
                            char RandChar = keyWords[mainrand.Next(0, MaxValue)];
                            result += RandChar;
                            Seed += DateTime.Now.Millisecond + Seed - new Random().Next(10) + new Random(DateTime.Now.Millisecond + 800 * 989 / 3).Next(10);
                        }
                        catch { continue; }
                    }
                }
                catch { }
                return result;
            }

    Вместо одного вызова Path.GetRandomFileName

    psina-from-ua, 28 Октября 2012

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

    +175

    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
    public static IEnumerable<float> Single(float from, float to, float step)
            {
                if (step <= 0.0f) step = (step == 0.0f) ? 1.0f : -step;
     
                if (from <= to)
                {
                    for (float f = from; f <= to; f += step) yield return f;
                }
                else
                {
                    for (float f = from; f >= to; f -= step) yield return f;
                }
            }
     
    public static IEnumerable<double> Double(double from, double to, double step)
            {
                if (step <= 0.0) step = (step == 0.0) ? 1.0 : -step;
     
                if (from <= to)
                {
                    for (double d = from; d <= to; d += step) yield return d;
                }
                else
                {
                    for (double d = from; d >= to; d -= step) yield return d;
                }
            }

    Такие методы накопированы для всех типов данных, которые известны поциенту.
    Но особо интересны эти джва метода

    Unlike some other programmimg languages (notably F#), C# doesn't have any built-in support for dealing with ranges of numbers. The .NET Framework does have the Enumerable.Range() method.
    - It can only deal with Int32's.
    - You can't specify a 'step' from one element of the range to the next. In effect, the step is always one. In this article, I'd therefore like to present a static Range class to deal with these deficiencies.

    http://www.c-sharpcorner.com/uploadfile/b942f9/dealing-with-ranges-of-numbers-in-C-Sharp

    3.14159265, 26 Октября 2012

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

    +139

    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
    public string WorkerSexWord
            {
                get
                {
                  if(WorkerSex == true)
                  {
                      return "м";
                  }
                  if(WorkerSex == false)
                  {
                      return "ж";
                  }
                    return "";
                }
            }

    "м" или "ж" выбор с булевого поля

    bercerker, 25 Октября 2012

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