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

    +142

    1. 1
    2. 2
    3. 3
    return ("" + ((10 - (acn = "229" + acn)
                            .Select((c, с) => (int)(c - '0') * (с % 2 + 1))
                            .Sum(c => c / 10 + c % 10) % 10) % 10)).Insert(0, acn);

    symon, 18 Июня 2015

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

    +145

    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
    public string define(string content)
        {
                    int till;
                    char[] CharArr = content.ToCharArray();
                    for (int i = 0; i < CharArr.Length; i++)
                    {
                        if (CharArr[i] == 'i')
                        {
                            till = i;
                        }
                    }
                    string Re = content.Substring(0,till);
                    return Re;
                }

    С тостера. Я рыдал.

    planaric, 18 Июня 2015

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

    +145

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    protected virtual void OnDisconnected()
    {
    		DispatcherHelper.CheckBeginInvokeOnUI(() =>
    		{
    			...
    			Cameras.ToList().Clear();
    			Meltings.ToList().Clear();
    			Spans.ToList().Clear();
    			...
    		});
    }

    Очищаем коллекции с данными, привязанные на списковые контролы UI. Доступ к свойствам Cameras, Meltings, Spans только через IEnumerable<>. Как же их очистить?

    elmanav, 18 Июня 2015

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

    +144

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public static class BoolExt
        {
            public static string ToYesNoString(this bool value)
            {
                return value ? "Да" : "Нет";
            }
        }

    alexCoder2007, 17 Июня 2015

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

    +143

    1. 1
    2. 2
    3. 3
    4. 4
    public static bool IsEmpty(this string input)
            {
                return String.IsNullOrEmpty(input);
            }

    А почему бы и да?

    alexCoder2007, 17 Июня 2015

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

    +141

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    string log;
    ...
    try
    {
              Logger.SaveLog(fullPath, log);
    }
    catch (Exception ex)
    {
             Logger.SaveLog(fullPath, ex.ToString());
    }

    Senior developer...

    kiberg, 16 Июня 2015

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

    +142

    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
    public void AllocateMemory(ref int[] segmentSizeProcess)
            {
                int[] difference;
                int j = 0;
                int tempo = 0;
    
                for (int i = 0; i < segmentSizeProcess.Count(); i++)
                {
                    difference = new int[memory.Count]; // храним разность размера блока памяти и требуемого размера для процесса
                    for (int count = 0; count < memory.Count; count++)
                    {
                        difference[count] = -2; // предварительно инициализируем 
                    }
                    for (int count_memory=0; count_memory<memory.Count();
                        count_memory++)
                    {
                        if (memory[count_memory].size - segmentSizeProcess[i] >= 0) // если равно 0, значит 
                        // сегмент полностью распределён
                        {
                            if (!memory[count_memory].isAllocate)
                            { difference[count_memory] = memory[count_memory].size - segmentSizeProcess[i]; }
                            else
                            { difference[count_memory] = -1; } // если сегмент занят - 
                            // то он недоступен
                        }
                    }
                    tempo = GetMinDifference(ref difference); // получаем индекс минимальной разности
                    // если результат "-", значит секторы заняты, выходим из цикла
                    if (difference[tempo] >= 0)
                    {
                        memory.ElementAt(tempo).isAllocate = true; // процесс занял сегмент
                        if (difference[tempo] > 0) // если остаётся фрагмент памяти
                        {
                            CreateDifferenceSegment(difference[tempo]); // создаем новый сегмент, равный
                            // наименьшей разности памяти сегмента и памяти для процесса
                        }
                            memory[tempo].size = segmentSizeProcess[i]; // распределяем память
                    }
                    else
                    {
                        break;
                    }
                }
            }

    Примерная реализация алгоритма best-fit

    qstd, 15 Июня 2015

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

    +142

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    public class Generator
        {
            private Random R = new Random();
            public Generator() 
            { 
                
            }
            public int GetNumber(int left, int right)
            {
                return R.Next(left, right);
            }
        }

    Полезный класс

    tarasfromgomel, 13 Июня 2015

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

    +143

    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
    System.String origString;
    System.Int32 index;
    System.Console.WriteLine("Введите строку: ");
    origString = System.Console.ReadLine();
    
    System.Int32 length = 0;
    for (int i = 0; i < origString.Length; i++)
        length++;
    
    System.Console.WriteLine("Какую букву вычесть?: ");
    index = System.Console.Read() - 49;
    System.Char[] newString = new System.Char[origString.Length];
    
    for (int i = 0; i < length; i++)
    {
        if (i != index && index != i && i != null && index != null)
        {
            newString[i] = origString[i];   
        }
        if (i == index && index == i && i != null && index != null)
        {
            newString[i] = Convert.ToChar(7);
        }
    }
    
    System.Console.Write("Результат: ");
    
    length = 0;
    for (int i = 0; i < newString.Length; i++)
        length++;
    for(int i = 0; i < length; i++)
        System.Console.Write(newString[i]);
    
    System.Console.ReadLine();
    System.Console.ReadLine();

    Ответ на вопрос на toster.ru
    Как сделать это на c#?
    Вычеркните i-ю букву заданной строки
    https://toster.ru/q/222727

    limited_ed, 06 Июня 2015

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

    +142

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    var leftDate = GetAll().Select(i => i.SaveDateTime).OrderBy(i => i).FirstOrDefault();
    var rigthDate = GetAll().Select(i => i.SaveDateTime).OrderByDescending(i => i).FirstOrDefault();
    
    // 1e7 - количество тактов в секунде (а в итоге: проверка разницы в неделю)
    while (rigthDate.Ticks - leftDate.Ticks > 1e7 * 60 * 60 * 24 * 7)
    {
    ....................................
    }

    с точностью до тика.

    andrewiv, 05 Июня 2015

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