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

    +114

    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
    public IQueryable<Log> Select(Context context)
            {
                // Return list of entities
                return (from l in context.Logs select l);
            }
    
            /// <summary>
            /// Fetch page from Log table
            /// </summary>
            /// <param name="nStartRowIndex">Starting index of rows to fetch</param>
            /// <param name="nMaxRows">Max number of rows</param>
            /// <returns>IEnumerable of Log</returns>
            public List<Log> SelectPage(int nStartRowIndex, int nMaxRows, 
                                        string strProperty, string strKeyword,
                                        string strSort, string strSortDirection, 
                                        out int nTotalCount)
            {            
                using (Context context = new Context())
                {
                    var q = Select(context).Take (1000);
                 }
          }

    Коллега на работе наворотил...

    Katsy, 04 Февраля 2011

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

    +146

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    static void WriteToFile()
    {
    StreamWriter SW;
    SW=File.CreateText("c:\\MyTextFile.txt");
    SW.WriteLine("God is greatest of them all");
    SW.WriteLine("This is second line");
    SW.Close();
    Console.WriteLine("File Created SucacessFully");
    }

    SucacessFully, что здесь непонятного!)
    А строки 3 и 4 стоило написать в одну строчку сразу.
    Источник: http://www.csharphelp.com/2005/12/simple-text-file-operations-in-c/

    RaZeR, 03 Февраля 2011

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

    +131

    1. 1
    DateTime dt = DateTime.Parse(DateTime.Now.ToString("dd.MM.yyyy"));

    Вот такие гении встречаются в нашей местности....

    Buzurud, 03 Февраля 2011

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

    +116

    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
    namespace Containers
    {
        public class TBinaryWaitingQueue<TItem> where TItem : struct
        {
            private readonly TBinaryQueue<TItem> _queue;
            TBinaryWaitingQueue(int amountOfitem)
            {
                _queue = new TBinaryQueue<TItem>(amountOfitem);
            }
    
            public void Enqueue(TItem[] items)
            {
                throw new NotImplementedException();
            }
    
            public void Enqueue(TItem[] items, int beginItem, int amountOfItem)
            {
                throw new NotImplementedException();
            }
    
            public void Dequeue(TItem[] items, int beginItem, int amountOfItem)
            {
                throw new NotImplementedException();
            }
    
            public TItem[] Dequeue(int amountOfItem)
            {
                throw new NotImplementedException();
            }
        }
    }

    Досталось в наследство от предков. Этому коду уже года 4.

    Говногость, 03 Февраля 2011

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

    +118

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    public class TWriteableForEach
    	{
    		public delegate void TForEachDelegate<TItem>(TItem item);
    
    		public static void Exec<TItem>(IList<TItem> itemsCollection, TForEachDelegate<TItem> forEachDelegate)
    		{
    			for (int i = 0; i < itemsCollection.Count(); ++i)
    				forEachDelegate(itemsCollection[i]);
    		}
    	} ;

    Велосипед с квадратными колёсами?

    Говногость, 03 Февраля 2011

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

    +116

    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
    public class TObjects
    	{
    		public delegate T DeferredConstruction<out T>();
    
    		public static void Dispose<T>(ref T objectForDispose)
    		{
    			var typeOfObjectForDispose = typeof(T);
    			if (!typeOfObjectForDispose.IsClass)
    				DisposeIfIDisposable(ref objectForDispose, typeOfObjectForDispose);
    			else
    				if (!Equals(objectForDispose, null))
    					DisposeIfIDisposable(ref objectForDispose, typeOfObjectForDispose);
    			objectForDispose = default(T);
    			//objectForDispose = (T)(object)(null);
    		}
    
    		public static void Create<T>(ref T objectForCreate, DeferredConstruction<T> newObject)
    		{
    			Dispose(ref objectForCreate);
    			objectForCreate = newObject();
    		}
      private static void DisposeIfIDisposable<T>(ref T objectForDispose, Type typeOfObjectForDispose)
            {
                bool canDisposable = (objectForDispose as IDisposable) != null;
                if (canDisposable)
                {
                    var dispose = typeOfObjectForDispose.GetMethod("Dispose");
                    dispose.Invoke(objectForDispose, new object[] { });
                }
            }
    }

    Говногость, 03 Февраля 2011

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

    +128

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    public class TDebug
    	{
    		public static void Assert(bool condition)
    		{
    			System.Diagnostics.Debug.Assert(condition);
    #if DEBUG
    			if(!condition)
    				throw new Exception();
    #endif
    		}
    	}

    Говногость, 03 Февраля 2011

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

    +127

    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
    class TStopThreadWaiter
    	{
    		public static void Wait(Thread threadWaitededForStop)
    		{
    			var threadName = threadWaitededForStop.GetType().Name;
    			if (!threadWaitededForStop.Join(1000))
    			{
    				TErrorShower.ShowOnceIfAgree("Неудаёться остановить " + threadName + " поток. Будут предприняты попытки внештатной остановки.");
    				if (!threadWaitededForStop.Join(200))
    					threadWaitededForStop.Interrupt();
    				if (!threadWaitededForStop.Join(200))
    				{
    					TErrorShower.ShowOnceIfAgree(threadName + " поток не удалость остановить принудительно через Interrupt. Предпринимаю попытку принудительной остановки через Abort.");
    					threadWaitededForStop.Abort();
    					if (!threadWaitededForStop.Join(200))
    					{
    						TErrorShower.ShowOnceIfAgree(threadName + " поток не удалость остановить принудительно через Abort. Завершаем приложение.");
    						Application.Exit();
    					}
    				};
    			};
    		}
    	}

    Говногость, 03 Февраля 2011

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

    +136

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    while (f != null && !string.IsNullOrEmpty(f.FileName) && f.ContentLength != 0)
    {
       if (f != null && !string.IsNullOrEmpty(f.FileName) && f.ContentLength != 0)
       {
          // ...
       }
    }

    Проверка на всякий случай

    ReallyBugMeNot, 02 Февраля 2011

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

    +128

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    //Hint: We have added one more overload to the method Load/LoadBinary/LoadSoap to achieve your requirement. Please refer the below code snippet.
    
    Exception ex = null;
    diagram1.LoadBinary(@"..\\..\\Basic Shapes.edp",out ex);
    if (ex != null)
    {
    //Do your customization here
    }

    индусский обработчик исключений.
    поддержка исключений в их компонент была добавлена по нашей просьбе.

    kjuby2, 01 Февраля 2011

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