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

    +6

    1. 1
    2. 2
    3. 3
    4. 4
    public string GetRegion(CallContext context)
    {
          return "Регион";
    }

    hinduCoder, 29 Февраля 2016

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

    +6

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    using System;
    namespace Colculator
    {
        public partial class Form1 : Form
        {
               bool BOOL = {
                     true,true,true,true,true,true,true,false};
               if(BOOL(new Random(1,8)){
                          Consosle.WriteLine("ДА");
    }

    Так делать нельзя!!!

    sliper, 28 Февраля 2016

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

    +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
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    if ( text.Contains( "лет" ) || text.Contains( "год" ) )
    {
    	var match = Regex.Match( text, @"\d+", RegexOptions.Singleline );
    	if ( !match.Success )
    		return null;
    	var date = DateTime.UtcNow;
    	return date.AddYears( -Int32.Parse( match.Value ) );
    }
    else if ( text.Contains( "дн" ) || text.Contains( "ден" ) )
    {
    	var match = Regex.Match( text, @"\d+", RegexOptions.Singleline );
    	if ( !match.Success )
    		return null;
    	var date = DateTime.UtcNow;
    	return date.AddDays( -Int32.Parse( match.Value ) );
    }
    else if ( text.Contains( "месяц" ) )
    {
    	var match = Regex.Match( text, @"\d+", RegexOptions.Singleline );
    	if ( !match.Success )
    		return null;
    	var date = DateTime.UtcNow;
    	return date.AddMonths( -Int32.Parse( match.Value ) );
    }
    else if ( text.Contains( "час" ) )
    {
    	var match = Regex.Match( text, @"\d+", RegexOptions.Singleline );
    	if ( !match.Success )
    		return null;
    	var date = DateTime.UtcNow;
    	return date.AddHours( -Int32.Parse( match.Value ) );
    }
    else if ( text.Contains( "недел" ) )
    {
    	var match = Regex.Match( text, @"\d+", RegexOptions.Singleline );
    	if ( !match.Success )
    		return null;
    	var date = DateTime.UtcNow;
    	return date.AddHours( ( -Int32.Parse( match.Value ) ) * 7 );
    }
    else if ( text.Contains( "минут" ) )
    {
    	var match = Regex.Match( text, @"\d+", RegexOptions.Singleline );
    	if ( !match.Success )
    		return null;
    	var date = DateTime.UtcNow;
    	return date.AddMinutes( -Int32.Parse( match.Value ) );
    }
    return null;

    Копипаста >_< До кучи ещё и с классической copy-paste ошибкой в логике.

    HellBrick, 28 Февраля 2016

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

    −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
    if (p != null)
    {
        Thread thread = new Thread(() =>
        {
            StaffList.App.Controls.Personal.PersonRec rec = new Controls.Personal.PersonRec();
            rec.DataContext = p;
            rec.Mode = StaffList.Controls.OperatingMode.Show;
            var win = new BaseWindow();
            win.Form = rec;
            win.ShowDialog();
        });
    
        thread.SetApartmentState(ApartmentState.STA);
        thread.Start();
    }

    Это мы так делаем немодальные окна.

    kerman, 25 Февраля 2016

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

    +10

    1. 1
    2. 2
    3. 3
    4. 4
    public static string toFormat(string s, int u)
    {
        return "                                                                       ".Substring(0, u * 4) + s +"\r\n";
    }

    Функция используется для форматирования файла класса, созданного автоматически.

    deathguard771, 25 Февраля 2016

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

    +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
    if (t.IsFaulted)
    {
        try
        {
            throw t.Exception.InnerException;
        }
        catch (ObjectDisposedException)
        {
            Dispose();
            return;
        }
        ...
    }

    cykablyad, 24 Февраля 2016

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

    −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
    public async Task AddOrUpdateAsync<T>(string key, T value) where T : class
     {
          ConcurrentQueue<T> queue = null;
          await Task.Run(() =>
          {
                var cacheItem = _cache.GetCacheItem(key);
                if (cacheItem != null)
                {
                    queue = cacheItem.Value as ConcurrentQueue<T>;
                 }
            });
            await Task.Run(() => queue.Enqueue(value));
     }

    типа кусок из добавления нового элемента в кэш. Стильно, модно, асинхронно!

    ivli, 15 Февраля 2016

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

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    private bool IsDriverSuccessfullyInstalled(DriverInfo di, string historyDriverVersion, string historyPackageVersion)
    {
      bool flag = false;
      if (!string.IsNullOrWhiteSpace(di.VersionAfterInstallation) && !string.IsNullOrWhiteSpace(di.VersionAfterInstallation) && new Version(di.VersionAfterInstallation).CompareTo(new Version(di.VersionBeforeInstallation)) >= 0)
    	flag = true;
      return flag;
    }

    При попытке поставить драйвер интеловской видюхи инсталлер вывалился с ArgumentNullException. Декомпильнул его и увидел вот это.
    Копипаста головного мозга.

    yamamoto, 13 Февраля 2016

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

    −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
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    //------------------------------------------------------------------------------
    // <auto-generated>
    //    This code was generated from a template.
    //
    //    Manual changes to this file may cause unexpected behavior in your application.
    //    Manual changes to this file will be overwritten if the code is regenerated.
    // </auto-generated>
    //------------------------------------------------------------------------------
    
    using System.Collections.ObjectModel;
    using System.Linq;
    
    namespace DemoFeb2014.DataContexts
    {
        using System;
        using System.Collections.Generic;
        
        public partial class Author
        {
           ....
    
      public ICollection<Tuple<MusicalWork, string>> Author2MusicalWorkParsed
            {
                get
                {
                   ...
                }
            }
            
        }
    }

    Спасибо коллегам! Благодаря только им можно потратить полчаса времени на розыск коммита в котором пропал метод Author2MusicalWorkParsed и выяснения причин того, почему же он пропал...
    Видимо комментарии в начале файла недостаточно "жирные".

    leon_mz, 12 Февраля 2016

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

    +7

    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
    static int[] Compute(int[] array) 
    { 
    int count = array.Length; 
    int[] result = new int[count]; 
    
    for (int i = 0, j = 0, mul = 1; i < count; ++i, j = 0, mul = 1) 
    { 
    for (; j != i; ++j) 
    mul *= array[j]; 
    
    for (++j; j != count; ++j) 
    mul *= array[j]; 
    
    result[i] = mul; 
    } 
    return result; 
    }

    Ибо нефиг писать такие шарпи у for

    d_fomenok, 11 Февраля 2016

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