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

    +943.7

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    static string ConCat(string str0,string str1)
            {
                if (str0 is string && str1 is string) return str0 + str1;
                else return null;
            }

    А вдруг НЕ строку подсунут....

    psina-from-ua, 04 Января 2010

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

    +105.2

    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
    public static bool EqualHash(string x, string y)
            {
                if ((x == null || y == null) && x != y)
                    return false;
    
                if (x == null && x == y)
                    return true;
                
                if (x.Length != y.Length)
                    return false;
                
                for (int i=0; i<x.Length; i++)
                {
                    if (x[i] == y[i])
                        return false;
                }
    
                return true;
            }
    
    //чуть ниже в том же классе
    
            public static bool SimpleEqualHash(string x, string y)
            {
                return (x == y);
            }

    sven47, 04 Января 2010

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

    +134.5

    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
    static void Main(string[] args)
            {
                if (args.Length < 1)
                    Console.WriteLine("Usage:\n\tprogram <Folder> [output file]");
                else if (args.Length == 1)
                {
                    string outf = args[0] + "\\output.txt";
                    System.IO.File.WriteAllLines
                        (
                            outf,
                            new List<string>
                                (
                                    System.IO.Directory.GetFiles(args[0])
                                )
                                    .Concat(System.IO.Directory.GetDirectories(args[0]))
                                    .ToArray()
                        );
                }
                else if(args.Length == 2)
                {
                    string outf = args[1];
                    System.IO.File.WriteAllLines
                        (
                            outf,
                            new List<string>
                                (
                                    System.IO.Directory.GetFiles(args[0])
                                )
                                    .Concat(System.IO.Directory.GetDirectories(args[0]))
                                    .ToArray()
                        );
                }
            }

    Видите ли, я не знал как это сделать с помощью скриптовых языков виндовс.

    psina-from-ua, 01 Января 2010

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

    +950.3

    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
    //...
    for (int i = 0; i < arr.Length; i++)
    {
          if (i == 5)
          {
                 if (arr[i] == -1)
                 {
                        break;
                 }
                 else
                 {
                        return -1;
                 }
          }
          else continue;
    }
    //...

    FMB, 31 Декабря 2009

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

    +131.4

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    internal static System.Drawing.Font ToWindowsFont(Microsoft.Office.Interop.PowerPoint.Font ppFont)
    {
    	FontStyle style = ToGdiFontStyle(ppFont.Style);
    	System.Drawing.Font gdiFont = new System.Drawing.Font(ppFont.Name, ppFont.Size, style);
    	// из-за следующей строчки проект не скомпилируется под .NET 2.0, требуя ещё и один из более новых SP
    	if ( windowsFont.Name != windowsFont.OriginalFontName )
    	{
    		windowsFont = new System.Drawing.Font(TextConverter.DefaultUnicodeSubstituteFont, ppFont.Size, style);
    	}
    	return windowsFont;
    }

    Баг был случайно найден на виртуалке с чистой Windows XP и MS Visual Studio 2005, поскольку мы по собственной глупости упустили тот факт, что на хост-машинах давно стоит .NET 3.5. Строчка "if ( windowsFont.Name != ppFont.Name )" решает проблему совместимости. Вот как иногда из-за маленькой, не бросающейся в глаза, ошибки можно завалить весь проект. Каюсь, этот код - мой. ))

    cyba, 31 Декабря 2009

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

    +132.4

    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
    var ChildListWithCondition =
                    (from list in ChildList
                     join requestedRelatedEntityIds in EntitiesIdInList on list.ParentEntityId equals requestedRelatedEntityIds
                     join requestedEntityType in EntityTypeIdToTake on list.EntityTypeId equals requestedEntityType)
                     .Select(list => 
                         new LayoutDataOutputStructure()
                         {
                             ParentEntityId = list.ParentEntityId,
                             EntityId = list.EntityId,
                             FieldId = list.FieldId,
                             FieldValue = list.FieldValue,
                             EntityTypeId = list.EntityTypeId,
                             RelationTypeToParent = list.RelationTypeToParent,
                             FieldValueId = list.FieldValueId
                         })
                    .GroupBy(item => item.ParentEntityId)
                    .Select(group => new
                        {
                            ParentEntityId = group.Key,
                            GroupEntityTypeId = group.GroupBy(item => item.EntityTypeId)
                                .Select(group2 => new
                                                     {
                                                        EntityTypeId = group2.Key,
                                                        EntityRelation = group2.Select(item => item.RelationTypeToParent).FirstOrDefault(),
                                                        GroupEntityId = group2.GroupBy(group3 => group3.EntityId)
                                                            .Select(group3 => new
                                                                                  {
                                                                                      EntityId = group3.Key, 
                                                                                      Fields = group3.GroupBy(group4 => group4.FieldId)
                                                                                        .Select(group4 => new { FieldId = group4.Key, FieldValues = group4 })
                                                                                        
                                                                                  })
                                                     }
                                    )
                        }
                    )
                    .ToList();

    workgss, 29 Декабря 2009

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

    +135.4

    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
    public static BitmapImage ConvertBitmapToBitmapImage(Bitmap bitmap)
            {
                var bitMapImage = new BitmapImage();
                var ms = new MemoryStream();
    
                try
                {
                    bitmap.Save(ms, ImageFormat.Bmp);
                    bitMapImage.BeginInit();
                    bitMapImage.StreamSource = ms;
                    bitMapImage.EndInit();
                }
                catch (NotSupportedException e)
                {
                    try
                    {
                        bitMapImage = new BitmapImage();
                        bitmap.Save(ms, ImageFormat.Png);
                        bitMapImage.BeginInit();
                        bitMapImage.StreamSource = ms;
                        bitMapImage.EndInit();
                    }
                    catch (NotSupportedException e2)
                    {
                        bitMapImage = new BitmapImage();
                        bitmap.Save(ms, ImageFormat.Bmp);
                        ms.Write(ms.ToArray(), 78, (int)(ms.Length - 78));
                        bitMapImage.BeginInit();
                        bitMapImage.StreamSource = ms;
                        bitMapImage.EndInit();
                    }
                }
    
                return bitMapImage;
            }

    wpf + System.Drawing + sql и хз что со всем этим делать )))))

    walash, 28 Декабря 2009

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

    +127.8

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    public static int not(this int i)
    {
          string i2 = Convert.ToString(i, 2),
         res = "";
          foreach (char c in i2)
                res += c == '0' ? '1' : '0';
          return Convert.ToInt32(res, 2);
    }

    Дело было вечером, делать было нечего....

    psina-from-ua, 24 Декабря 2009

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

    +103

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    MessageBox.Show(
     a.Decode(
      new StringBuilder(
       a.Encode(
         new StringBuilder(
           textBox1.Text)).ToString())).ToString());

    Говнокод... ну почти говнокод. Думаю, замечание.

    ajukraine, 22 Декабря 2009

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

    +96.1

    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
    [TestFixture]
        class Program
        {
            static void Main(string[] args)
            {
                .................   
            }
        }
    
        [TestFixture]
        internal class FileParser
        {
            [Test]
            private static string Replace(string inputValue, string oldWord,string newWord)
            {
                return inputValue.Replace(oldWord, newWord);
            }
    
            [Test]
            private static string Remove(string inputValue, string word)
            {
                return inputValue.Replace(word, null);
            }
    
            [Test]
            public string Run(string stringFromFile)
            {
                foreach (var command in _listOfCommands)
                {
                    switch (command.IdCommand)
                    {
                        case 0:
                            stringFromFile = Replace(stringFromFile, command.OldWord, command.NewWord);
                            break;
                        case 1:
                            stringFromFile = Remove(stringFromFile, command.NewWord);
                            break;
                    }
                }
                return stringFromFile;
            }
        }

    программист слишком буквально понял TestDrivenDevelopment :)) взято из консольного приложения

    explosion_head, 19 Декабря 2009

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