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

    +135

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    public static byte[] ConvertStringToByteArray(string str)
    {
    	int i, n;
    	n = str.Length;
    	byte[] x = new byte[n];
    	for (i = 0; i < n; i++)
    	{
    		x[i] = (byte)str[i];
    	}
    	return x;
    }

    Парни я не знаю баян это или нет, я лично не видел, но сторожилам виднее

    Smekalisty, 08 Сентября 2014

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

    +133

    1. 1
    body = Regex.Replace(Regex.Replace(x.SubTitle ?? "...", @"@\[", ""), @"\]\(([^:]+):(\d+)\)", "");

    как индусы юзают регулярки

    movsesiv, 08 Сентября 2014

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

    +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
    39. 39
    40. 40
    public string ExportToFile(string filename, string filepath, DataSet dsInput)
     {
         string sFlag = "Error";
         System.IO.StreamWriter sw = new StreamWriter("");
         try
         {
             if (filename.Trim() != "" && filepath != "" && dsInput.Tables[0].Rows.Count != 0)
             {
                    sw = new System.IO.StreamWriter(filepath + filename + ".xls");
                     int iCol = dsInput.Tables[0].Columns.Count;
                     for (int i = 0; i < iCol; i++)
                     {
                         sw.Write(dsInput.Tables[0].Columns[i]);
                         if (i < iCol - 1)
                         { sw.Write("\t"); }
                     sw.Write(sw.NewLine);
                     foreach (DataRow dr in dsInput.Tables[0].Rows)
                     {
                         for (int i = 0; i < iCol; i++)
                         {
                             if (!Convert.IsDBNull(dr[i]))
                             {
                                 sw.Write(dr[i].ToString());
                             }
                             if (i < iCol - 1)
                             { sw.Write("\t"); }
                         }
                         sw.Write(sw.NewLine);
                     }
                     sw.Close();
                     sFlag = "Success";
                 }
             }
             return sFlag;
         }
         catch (Exception)
         {
             return sFlag;
         }
     }

    С какого-то китайского сайта:
    http://www.datazx.cn/Forums/en-US/2d129cdc-2705-4035-90e2-063c4c399ae5/action?threadDisplayName=wpf-datagrid-remove-whitespace-from-string-on-clipboard-copy&forum=wpf
    Нафиг эксепшены, лучше вернем строку "Error"! Ну или "Success", если этот чудо-код еще и не грохнется.

    yamamoto, 05 Сентября 2014

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

    +134

    1. 1
    2. 2
    if (paramList[i].GetType().Equals(typeof(String)))
    ...

    musuk, 04 Сентября 2014

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

    +133

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    //You can assign Values to the ASPNET RadioButton like this way:
    protected void Page_Load(object sender, EventArgs e)
     {
             RadioButton1.Attributes.Add("value", "ASPNET");
    } 
    
    //Then you can access the value this way:
    protected void Button1_Click(object sender, EventArgs e)
     {
             Response.Write(RadioButton1.Attributes["value"].ToString());
    }

    сегодня для меня стало новостью, что у высокоуровневого контрола asp.net web form RadioButton, который по сути рендерится в <input type="radio">, нет атрибута value.
    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.radiobutton(v= vs.110).aspx да, его нет.
    но сначала я подумал, что все же может это я кривой и не туда смотрю, а потом нахожу велосипед, который предлагает MVP http://forums.asp.net/t/1379187.aspx?Why+does+an+ASP+NET+RadioBu tton+control+not+have+a+property+to+prog ramatically+set+the+value+attribute+

    Lokich, 02 Сентября 2014

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

    +132

    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
    private const double A = -695.0;
    
            private const double B = 1136.0;
    
            private const double C = 172018;
    через 10 строк:
     topPanel.SplitterDistance = (int)
                                                Math.Round(
                                                    (-A*ApplicationDispatcher.Current.ApplicationContainer.Size.Width - C)/B,
                                                    MidpointRounding.AwayFromZero) - 5;
    
    и дальше внутри , где-то через 200 строк
    
     topPanel.SplitterDistance = (int)
                                                Math.Round(
                                                    (-A * ApplicationDispatcher.Current.ApplicationContainer.Size.Width - C) / B,
                                                    MidpointRounding.AwayFromZero) - 5;
    больше нигде не используется

    zxxc, 01 Сентября 2014

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

    +133

    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
    private void button1_Click(object sender, EventArgs e)
             {
                 OpenFileDialog ofd = new OpenFileDialog();
                 if(ofd.ShowDialog() == DialogResult.OK)
                 {
                     gs_path = ofd.FileName;
                     BinaryReader br = new BinaryReader(new FileStream(gs_path, FileMode.Open, FileAccess.Read));
                     int sys = 0;
                     do {
                         ofset++;
                         br.BaseStream.Seek(ofset, SeekOrigin.Begin);
                         if (br.ReadInt64() == 6875716118506401907)
                         {
                             if (br.ReadInt64() == 521392779117)
                             {
                                 sys = 1;
                             }
                         }
                     } while (sys == 0);
                     br.BaseStream.Seek(ofset + 20, SeekOrigin.Begin);
                     textBox1.Text = br.ReadSingle().ToString();
                     br.BaseStream.Seek(ofset + 24, SeekOrigin.Begin);
                     textBox2.Text = br.ReadSingle().ToString();
                     br.BaseStream.Seek(ofset + 28, SeekOrigin.Begin);
                     textBox3.Text = br.ReadSingle().ToString();
                     br.BaseStream.Seek(ofset + 32, SeekOrigin.Begin);
                     textBox4.Text = br.ReadSingle().ToString();
                     br.BaseStream.Seek(ofset + 36, SeekOrigin.Begin);
                     textBox5.Text = br.ReadSingle().ToString();
                     br.BaseStream.Seek(ofset + 40, SeekOrigin.Begin);
                     textBox6.Text = br.ReadSingle().ToString();
                     br.BaseStream.Seek(ofset + 44, SeekOrigin.Begin);
                     textBox7.Text = br.ReadSingle().ToString();
                     br.Close();
                 }
             }
    ...
            string gs_path;
             int ofset = 0;
             public Form1()
             {
                 InitializeComponent();
             }
    ...
            private void button2_Click(object sender, EventArgs e)
             {
                 BinaryWriter bw = new BinaryWriter(new FileStream(gs_path, FileMode.Open, FileAccess.Write));
                 bw.BaseStream.Seek(ofset + 20, SeekOrigin.Begin);
                 bw.Write(Convert.ToSingle(textBox1.Text));
                 bw.BaseStream.Seek(ofset + 24, SeekOrigin.Begin);
                 bw.Write(Convert.ToSingle(textBox2.Text));
                 bw.BaseStream.Seek(ofset + 28, SeekOrigin.Begin);
                 bw.Write(Convert.ToSingle(textBox3.Text));
                 bw.BaseStream.Seek(ofset + 32, SeekOrigin.Begin);
                 bw.Write(Convert.ToSingle(textBox4.Text));
                 bw.BaseStream.Seek(ofset + 36, SeekOrigin.Begin);
                 bw.Write(Convert.ToSingle(textBox5.Text));
                 bw.BaseStream.Seek(ofset + 40, SeekOrigin.Begin);
                 bw.Write(Convert.ToSingle(textBox6.Text));
                 bw.BaseStream.Seek(ofset + 44, SeekOrigin.Begin);
                 bw.Write(Convert.ToSingle(textBox7.Text));
                 bw.Close();
             }

    http://kn1fe-zone.ru/index.php?threads/%D0%9F%D1%80%D0%B8%D0%BC%D0%B5%D1%80-%D0%BF%D1%80%D0%BE%D0%B3%D1%80%D0%B0%D0% BC%D0%BC%D1%8B-%D1%81-%D0%B0%D0%B2%D1%82%D0%BE%D0%BF%D0%BE%D0% B8%D1%81%D0%BA%D0%BE%D0%BC-%D0%B7%D0%BD%D0%B0%D1%87%D0%B5%D0%BD%D0% B8%D0%B9.381/

    ХОСПАДИ ДЕСЯТЬ ИЗ ДЕСЯТИ!!!!1111 Принесите мачете и спирт!

    DesmondHume, 28 Августа 2014

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

    +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
    public static class GlobalFunc
    {
    	// bla-bla-bla ...
     
    	public static bool isDouble(string input)
    	{
    		Double dec;
    		return Double.TryParse(input, out dec);
    	}
    
    	public static bool isUShort(string input)
    	{
    		ushort dec;
    		return ushort.TryParse(input, out dec);
    	}
    
    	public static bool isShort(string input)
    	{
    		short dec;
    		return short.TryParse(input, out dec);
    	}
    
    	public static bool IsDate(string input)
    	{
    		DateTime date;
    		return DateTime.TryParse(input, out date);
    	}
    }

    face palm

    Smekalisty, 26 Августа 2014

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

    +126

    1. 1
    2. 2
    3. 3
    using питух = String;
    ...
    protected питух AccessToken { get; set; }

    В память о плавающем

    reshetochnik, 24 Августа 2014

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

    +124

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    class A
    {
    a:
    Console.WriteLine("Буква А");
    goto b;
    }
    Class B:A
    {
    b:
    Console.WriteLine("Буква Б");
    goto a;
    }

    Моему другу было нечего делать... Побробовал засорить мой комп.

    qwertyru, 23 Августа 2014

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