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

    +94

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    combinations.AddRange(combinations4);
                combinations.AddRange(from combination5 in combinations5
                                      where
                                          (from combination4 in combinations4
                                           where
                                               (from c4class in combination4.Classes
                                                where !combination5.Classes.Contains(c4class)
                                                select c4class).Count() == 0
                                           select combination4).Count() == 0
                                      select combination5);

    Теперь у меня есть ачивка "сделать через LINQ не смотря ни на что".
    Тому, кто поймёт, что же здесь происходит - достанется воображаемый пряник.

    krypt, 24 Января 2015

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

    +95

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public static class ColorExtension
    	{
    		public static bool IsDarkColor(this Color color)
    		{
    			return (color.R & 255) + (color.G & 255) + (color.B & 255) < 3*256/2;
    		}
    	}

    x & 255 = ?, где x типа byte

    schecterXA, 22 Января 2015

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

    +95

    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
    double[,] ThreadMatrixMult(int size, double[,] m1, double[,] m2)
            {
                double[,] result = new double[size, size];
                var threads = new List<Thread>(size);
                for (int i = 0; i < size; i++)
                {
                    var t = new Thread( ti =>
                    {
                        int ii = (int)ti;
                        for (int j = 0; j < size; j++)
                        {
                            result[ii, j] = 0;
                            for (int k = 0; k < size; k++)
                            {
                                result[ii, j] += m1[ii, k] * m2[k, j];
                            }
                        }
                    });
                    threads.Add(t);
                    t.Start(i);
                }
                
                foreach (Thread thread in threads)
                    thread.Join();
    
                return result;
            }

    LispGovno, 21 Января 2015

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

    +96

    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
    protected override void OnSourceInitialized(EventArgs e)
    {
        base.OnSourceInitialized(e);
        var hWndSource = (HwndSource)PresentationSource.FromVisual(this);
        Handle = hWndSource.Handle;
        hWndSource.AddHook(WndProc);
    }
    
    private const int WM_ACTIVATE = 0x0006;
    private const ushort WA_INACTIVE = 0;
    
    static ushort LOWORD(IntPtr I)
    {
        unchecked
        {
            return (ushort)(((uint)I) & 0xFFFF);
        }
    }
    
    protected IntPtr WndProc(IntPtr hWnd, int iMsg, IntPtr wParam, IntPtr lParam, ref bool bHandled)
    {
        switch (iMsg)
        {
            case WM_ACTIVATE:
                Opacity = LOWORD(wParam) == WA_INACTIVE ? 0.4 : 1.0;
                bHandled = true;
                return (IntPtr)1;
        }
    
        return IntPtr.Zero;
    }

    Из моего проекта. Так я писал код 0.8 год назад.
    Вместо того, чтобы использовать OnActivated и OnDeactivated.

    Janycz, 18 Января 2015

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

    +91

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    private static int NumberOfLeadingSpaces(string str)
    {
        str = str.TrimEnd();
        return str.Length - str.Trim().Length;
    }

    Из моего проекта. Так я писал код 1.5 год назад.
    Вместо того, чтобы пройтись циклом с начала строки, пока не встретиться символ, не являющийся пробелом.

    Janycz, 18 Января 2015

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

    +135

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public static string ExeDirectory
    {
        get
        {
            var strBuff1 = System.Windows.Forms.Application.ExecutablePath;
            var strBuff2 = Path.GetFileName(strBuff1);
            return strBuff1.Remove(strBuff1.Length - strBuff2.Length, strBuff2.Length);
        }
    }

    Из моего проекта. Так я писал код 1.5 год назад.

    Janycz, 18 Января 2015

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

    +133

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    var hContextMenu = (ContextMenu)MainDataGrid.Resources["CellContextMenu"];
    //UndoMenuItem.CommandTarget = MainDataGrid;
    UndoMenuItem.Command = ((MenuItem)hContextMenu.Items[0]).Command; //Undo
    //RedoMenuItem.CommandTarget = MainDataGrid;
    RedoMenuItem.Command = ((MenuItem)hContextMenu.Items[1]).Command; //Redo
    //CutMenuItem.CommandTarget = MainDataGrid;
    CutMenuItem.Command = ((MenuItem)hContextMenu.Items[3]).Command; //Cut
    //CopyMenuItem.CommandTarget = MainDataGrid;
    CopyMenuItem.Command = ((MenuItem)hContextMenu.Items[4]).Command; //Copy
    //PasteMenuItem.CommandTarget = MainDataGrid;
    PasteMenuItem.Command = ((MenuItem)hContextMenu.Items[5]).Command; //Paste

    Из моего проекта. Так я писал код год назад.

    Janycz, 18 Января 2015

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

    +126

    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
    class Program
        {
            static void Main(string[] args)
            {
                User admin = new User() { Name = "Admin", Dick = new User.UserDick(18) };
                User guest = new User() { Name = "guest", Dick = new User.UserDick(12) };
                Console.WriteLine(guest.Suck(admin.Dick));
                Console.ReadLine();
            }
        }
    
        public class User
        {
            public User() { }
            public class UserDick
            {
                public UserDick(int _length) { Length = _length; }
                public long Length { get; set; }
            }
            public string Name { get; set; }
            public UserDick Dick { get; set; }
    
            public string Suck(UserDick _dick)
            {
                return String.Format("{0}: OH YEAH FUCK ME BY YOUR {1} CM YEEEEEAH I WANNA SUCK YOUR {2} DICK!", Name, _dick.Length, _dick.Length >= 17 ? "BIG" : "SMALL");
            }
        }

    DesmondHume, 17 Января 2015

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

    +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
    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
    public enum Minutes
    	{
    		[Description("00")]
    		Zero = 0,
    
    		[Description("05")]
    		Five = 5,
    
    		[Description("10")]
    		Ten = 10,
    
    		[Description("15")]
    		Fifteen = 15,
    
    		[Description("20")]
    		Twenty = 20,
    
    		[Description("25")]
    		TwentyFive = 25,
    
    		[Description("30")]
    		Thirty = 30,
    
    		[Description("35")]
    		ThirtyFive = 35,
    
    		[Description("40")]
    		Forty = 40,
    
    		[Description("45")]
    		FortyFive = 45,
    
    		[Description("50")]
    		Fifty = 50,
    
    		[Description("55")]
    		FiftyFive = 55,
    	}

    schecterXA, 16 Января 2015

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

    +134

    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
    public enum Hours
    	{
    		[Description("01")]
    		One = 1,
    
    		[Description("02")]
    		Two = 2,
    
    		[Description("03")]
    		Three = 3,
    
    		[Description("04")]
    		Four = 4,
    
    		[Description("05")]
    		Five = 5,
    
    		[Description("06")]
    		Six = 6,
    
    		[Description("07")]
    		Seven = 7,
    
    		[Description("08")]
    		Eight = 8,
    
    		[Description("09")]
    		Nine = 9,
    
    		[Description("10")]
    		Ten = 10,
    
    		[Description("11")]
    		Eleven = 11,
    
    		[Description("12")]
    		Twelve = 12
    	}

    schecterXA, 16 Января 2015

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