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

    +129

    1. 1
    IsDirty = InitialLoad ? false : true;

    Классический индусокод, в исполнении расового полового индуса.

    VasyaMatros, 17 Сентября 2011

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

    +956

    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
    private void SetDisplay(string Group)
    {
           string taxInt = "144";
           switch (Group.ToLower())
           {
                  case "bond":
                         taxInt = "141";
                         ..............
                         break;
                  case "commodity":
                         taxInt = "329";
                         ..............
                         break;
                  case "emarkets":
                         taxInt = "142";
                         ..............
                         break;
                  default:
                         taxInt = "144";
                         ..............
                         break;
           }
           SetItems(taxInt);
    }
    
    public void SetItems(string taxInt)
    {
           Trace.Write(taxInt);
           int number;
           bool result = Int32.TryParse(taxInt, out number);
           if (result)
           {
                  tid = number;
           }
           else
           {
                  tid = 144;
                  this.lbHard.Style.Add("color", "#000");
           }
           Trace.Write(tid.ToString());
           if (tid > 0)
           {
                   ..............
            }
           else
           {
                   //здесь было пусто
           }
    }

    Лишний код удалён, оставлена только самая важная часть кода))

    dimon1988, 17 Сентября 2011

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

    +147

    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
    private void SetDisplay(string Group)
    {
           string taxInt = "144";
           switch (Group.ToLower())
           {
                  case "bond":
                         taxInt = "141";
                         ..............
                         break;
                  case "commodity":
                         taxInt = "329";
                         ..............
                         break;
                  case "emarkets":
                         taxInt = "142";
                         ..............
                         break;
                  default:
                         taxInt = "144";
                         ..............
                         break;
           }
           SetItems(taxInt);
    }
    
    public void SetItems(string taxInt)
    {
           Trace.Write(taxInt);
           int number;
           bool result = Int32.TryParse(taxInt, out number);
           if (result)
           {
                  tid = number;
           }
           else
           {
                  tid = 144;
                  this.lbHard.Style.Add("color", "#000");
           }
           Trace.Write(tid.ToString());
           if (tid > 0)
           {
                   ..............
            }
           else
           {
                   //здесь было пусто
           }
    }

    Лишний код удалён, оставлена только самая важная часть кода))

    dimon1988, 17 Сентября 2011

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

    +964

    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
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    using System;
    using System.Reflection;
    using System.Reflection.Emit;
    
    namespace DynUnloop
    { // Суммирование в цикле
      class SumLooping
      { public int Summ(int valMax)
        { int result = 0;
          for (int i = 0; i <= valMax; i++)
            result += i;
          return result;
        }
      }
    
      // Плоское суммирование
      class SumFlat
      { interface ISumCode
        { int ComputeSumm(int valMax);
        }
        void WriteCode(int valMax)
        { AssemblyName assemblyName = new AssemblyName();
          assemblyName.Name = "SumFlatAssembly";
    
          AssemblyBuilder assemblyBuilder = 
            AppDomain.CurrentDomain.DefineDynamicAssembly(
            assemblyName, AssemblyBuilderAccess.Run);
    
          ModuleBuilder moduleBuilder = 
            assemblyBuilder.DefineDynamicModule("SumFlatModule");
    
          TypeBuilder typeBuilder = 
            moduleBuilder.DefineType("SumFlatClass"
                        , TypeAttributes.Public);
    
          typeBuilder.AddInterfaceImplementation(typeof(ISumCode));
    
          /// Задаём возвращаемое зачение и параметр
          Type[] paramTypes = { typeof(int) };
          Type   returnType = typeof(int);
    
          MethodBuilder methodBuilder = 
            typeBuilder.DefineMethod("ComputeSumm"
              , MethodAttributes.Public 
              | MethodAttributes.Virtual
              , returnType, paramTypes);
    
          ILGenerator il = methodBuilder.GetILGenerator();
    
          // Генерируем плоский код.
          il.Emit(OpCodes.Ldc_I4, 0);
          for (int i = 1; i <= valMax; i++)
          { il.Emit(OpCodes.Ldc_I4, i);
            il.Emit(OpCodes.Add);
          }
          il.Emit(OpCodes.Ret);
    
          // Перекрываем метод ComputeSumm и создаём тип SumFlatClass.
          MethodInfo methodInfo = 
                     typeof(ISumCode).GetMethod("ComputeSumm");
          typeBuilder.DefineMethodOverride(methodBuilder, methodInfo);
          typeBuilder.CreateType();
    
          /// Код готов, создаём объект и берем его интерфейс.
          code = (ISumCode)assemblyBuilder.CreateInstance("SumFlatClass");
        }
    
        public int Summ(int val)
        { if (this.code == null)
            WriteCode(val);
          return this.code.ComputeSumm(val);
        }
    
        ISumCode code;
      }

    Оригинальный стиль кода и комментарии сохранёны. (с), или как там.
    В коде - разворачивание цикла в "плоский" IL код, который, как доказывается должен выигрывать по производительности.

    Elvenfighter, 13 Сентября 2011

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

    +147

    1. 1
    2. 2
    3. 3
    4. 4
    private void button5_Click(object sender, EventArgs e)
            {
                Application.Exit();
            }

    -.\\

    TERAB1T, 10 Сентября 2011

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

    +976

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public static bool MegaDispose(this IDisposable thіs)
    {
      if (thіs != null)
      {
        thіs.Dispose();
        return true;
      }
      return false;
    }

    CPPGovno, 05 Сентября 2011

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

    +972

    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
    str3 = "Insert Into orderList(OrderNo,Date,StoreName,TagCode,Size,Colour,TwoSidedEngraving,
    EngravingOptions,PetsName,PetsNameTwoSide,Phone1,Phone1TwoSide,Phone2,Phone2TwoSide,
    Phone3,Phone3TwoSide,OwnersFirstName,OwnersLastName,StreetAddress,Suburb,State,ZipCode,
    Country,MStreetAddress,MSuburb,MState,MZipCode,MCountry,OwnersFirstNameTwoSide,
    OwnersLastNameTwoSide,StreetAddressTwoSide,SuburbTwoSide,StateTwoSide,ZipCodeTwoSide,
    flag,Other9,idcust,Receiver,demo,databasename,isonline,faxfile) values(N'" + this.Request.Form["Orderno"] +
    "',Getdate(),N'" + Strings.Replace(this.Request.Form["storename"],"'", "''", 1, -1, CompareMethod.Binary) +
    "',N'" + str + "',N'" + this.Request.Form["tagSize"] + "',N'" + this.Request.Form["tagcolor"] + "',N'" +
    this.Request.Form["TwoSide"] + "',N'" + str2 + "',N'" +
    Strings.Replace(Strings.Replace(this.Convert(this.Request.Form["PetsName"]), "'", "''", 1, -1,
    CompareMethod.Binary), "\"", "\"", 1, -1, CompareMethod.Binary) + "',N'" +
    this.Request.Form["chbPetsName"] + "',N'" +
    Strings.Replace(Strings.Replace(Strings.UCase(this.Convert(this.Request.Form["Phone1"])), "'", "''",
    1, -1, CompareMethod.Binary), "\"", "\"", 1, -1, CompareMethod.Binary) + "',N'" +
    this.Request.Form["chbPhone1"] + "',N'" +
    Strings.Replace(Strings.Replace(Strings.UCase(this.Convert(this.Request.Form["Phone2"])),
    "'", "''", 1, -1, CompareMethod.Binary),
    "\"", "\"", 1, -1, CompareMethod.Binary) + "',N'" + this.Request.Form["chbPhone2"] + "',N'" +
    Strings.Replace(Strings.Replace(Strings.UCase(this.Convert(this.Request.Form["Phone3"])),
    "'", "''", 1, -1, CompareMethod.Binary),
    "\"", "\"", 1, -1, CompareMethod.Binary) + "',N'" + this.Request.Form["chbPhone3"] + "',N'" +
    Strings.Replace(Strings.Replace(Strings.UCase(this.Convert(this.Request.Form["FirstName"])),
    "'", "''", 1, -1, CompareMethod.Binary),
    "\"", "\"", 1, -1, CompareMethod.Binary) + "',N'" +
    Strings.Replace(Strings.Replace(Strings.UCase(this.Convert(this.Request.Form["LastName"])),
    "'", "''", 1, -1, CompareMethod.Binary),
    
    <ну и так далее...>
    
    this.Response.Write(function.ExecuteSql(str3));

    lucidfox, 05 Сентября 2011

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

    +122

    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
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    public class ASyncFileHashAlgorithm
    	{
    		protected HashAlgorithm hashAlgorithm;
    		protected byte[] hash;
    		protected bool cancel = false;
    		protected int bufferSize = 4096;
    		public delegate void FileHashingProgressHandler (object sender, FileHashingProgressArgs e);
    		public event FileHashingProgressHandler FileHashingProgress;
    
    		public ASyncFileHashAlgorithm(HashAlgorithm hashAlgorithm)
    		{
    			this.hashAlgorithm = hashAlgorithm;
    		}
    
    		public byte[] ComputeHash(Stream stream)
    		{
    			cancel = false;
    			hash = null;
    			int _bufferSize = bufferSize; // this makes it impossible to change the buffer size while computing
    
    			byte[] readAheadBuffer, buffer;
    			int readAheadBytesRead, bytesRead;
    			long size, totalBytesRead = 0;
    
    			size = stream.Length;
             	readAheadBuffer = new byte[_bufferSize];
                readAheadBytesRead = stream.Read(readAheadBuffer, 0, readAheadBuffer.Length);
    
                totalBytesRead += readAheadBytesRead;    
    
                do
                {
                    bytesRead = readAheadBytesRead;
                    buffer = readAheadBuffer;    
    
                    readAheadBuffer = new byte[_bufferSize];
                    readAheadBytesRead = stream.Read(readAheadBuffer, 0, readAheadBuffer.Length);
    
                    totalBytesRead += readAheadBytesRead;    
    
                    if (readAheadBytesRead == 0)
                        hashAlgorithm.TransformFinalBlock(buffer, 0, bytesRead);
                    else
                        hashAlgorithm.TransformBlock(buffer, 0, bytesRead, buffer, 0);
    
    				FileHashingProgress(this, new FileHashingProgressArgs(totalBytesRead, size));
                } while (readAheadBytesRead != 0 && !cancel);
    
    			if(cancel)
    				return hash = null;
    
        		return hash = hashAlgorithm.Hash;
    		}
    
    		public int BufferSize
    		{
    			get
    			{ return bufferSize; }
    			set
    			{ bufferSize = value; }
    		}
    
    		public byte[] Hash
    		{
    			get
    			{ return hash; }
    		}
    
    		public void Cancel()
    		{
    			cancel = true;
    		}
    
    		public override string ToString ()
    		{
    			string hex = "";
    			foreach(byte b in Hash)
    				hex += b.ToString("x2");
    
    			return hex;
    		}
    	}

    Очень интересная реализация "асинхронного" хэширования.

    martin, 31 Августа 2011

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

    +128

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    private static void ListXmlSerialize<T>(List<T> UserList, string Obj, string FileName)
    {
          object obj = new object();
          lock (obj)
          {
               XmlSerializer UserXmlFormat = new XmlSerializer(typeof(List<T>), Obj);
               Stream UserFileStream = new FileStream(FileName, FileMode.Create, FileAccess.Write, FileShare.Write);
               UserXmlFormat.Serialize(UserFileStream, UserList);
               UserFileStream.Close();
         }
    }

    wpfDev, 31 Августа 2011

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

    +965

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    string[] val = ...;
    if (val.Length > 0)
    {
        return val[1];
    }
    else
        return string.Empty;

    IndexOutOfRangeException

    Eugene, 31 Августа 2011

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