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

    +135

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    private void MultiSelectBox1_CheckedChanged(object sender, EventArgs e) {
               if (MultiSelectBox1.Checked == true) {
                    openFileDialog1.Multiselect = true;
                } else {
                    openFileDialog1.Multiselect = false;
                }
            }

    Lokich, 30 Августа 2013

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

    +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
    public DataTable ConvertToString(Array values, int col_length, int row_length, int counter) {
                DataTable dt = new DataTable();
                string[] theArray = new string[col_length];
                if (row_length < counter)
                    counter = row_length;
                for (int j = 1; j <= counter; j++) {
                    for (int i = 1; i <= col_length; i++) {
                        if (j == 1) {
                            try {
                                dt.Columns.Add(values.GetValue(j, i).ToString().Replace('.', '_'));
                            } catch (NullReferenceException nre) {
                                dt.Columns.Add("F" + i);
                            }
                        } else if (values.GetValue(j, i) == null)
                            theArray[i - 1] = "";
                        else
                            theArray[i - 1] = (string)values.GetValue(j, i).ToString();
                    }
                    if (j != 1)
                        dt.LoadDataRow(theArray, true);
    
                }
                return dt;
            }

    шедеврально, чтобы понять, есть ли значение в первой строке нужно словить NullReferenceException, а дальше можно проверить на != null
    и так же (string)values.GetValue(j, i).ToString();

    Lokich, 30 Августа 2013

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

    +128

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    if (null != this.messageTemplateResourceName && null != this.messageTemplateResourceType)
    {
        return ResourceStringLoader.LoadString(this.messageTemplateResourceType.FullName,
            this.messageTemplateResourceName,
            this.messageTemplateResourceType.Assembly);
    }
    if (null != this.messageTemplateResourceName || null != this.messageTemplateResourceType)
    {
        throw new InvalidOperationException(Resources.ExceptionPartiallyDefinedResourceForMessageTemplate);
    }

    Microsoft EnterpriseLibrary
    else? нет, не слышал

    NeoN, 29 Августа 2013

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

    +141

    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
    /// <summary>
    		/// Стартовый метод потока, который отображает процесс вычисления.
    		/// </summary>
    		public static void LoadingThread()
    		{
    			int curLoadingStep = 0;
    
    			while(!bStop)
    			{
    				Console.Clear();
    
    				switch(curLoadingStep)
    				{
    					case 0:
    						Console.WriteLine("Производится вычисление");
    						curLoadingStep = 1;
    					break;
    
    					case 1:
    						Console.WriteLine("Производится вычисление.");
    						curLoadingStep = 2;
    					break;
    
    					case 2:
    						Console.WriteLine("Производится вычисление..");
    						curLoadingStep = 3;
    					break;
    
    					case 3:
    						Console.WriteLine("Производится вычисление...");
    						curLoadingStep = 0;
    					break;
    				}
    
    				Thread.Sleep(800);
    			}
    		}

    Наткнулся на форуме.
    Чего то в этой жизни я явно не понимаю

    kegdan, 22 Августа 2013

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

    +137

    1. 1
    2. 2
    3. 3
    IServerRequest request = new ServerRequest(GetServerURL(serverType));
    
    if (request != null)

    На всякий случай.

    Belorus, 21 Августа 2013

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

    +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
    41. 41
    42. 42
    using System;
    using System.Threading;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication32
    {
        class Program
        {
            static readonly Random Random = new Random(DateTime.Now.Millisecond);
            private static int _counterTrue = 0;
            private static int _counterFalse = 0;
            private const int _MaxRand = int.MaxValue;
            private const int testLimit = 10000000;
    
            static void Main(string[] args)
            {
                Parallel.For(0, testLimit, (i) => Test());
                Console.WriteLine(_counterTrue);
                Console.WriteLine(_counterFalse);
                Console.WriteLine(_counterFalse/(float)(testLimit));
                Console.ReadKey();
    
            }
            static private void Test()
            {
                var first = Random.Next(_MaxRand);
                var second = Random.Next(_MaxRand);
                if (first == second)
                {
                    second = Random.Next(_MaxRand);
                }
                if (first == second)
                {
                    Interlocked.Increment(ref  _counterTrue);
                }
                else
                {
                    Interlocked.Increment(ref  _counterFalse);
                }
            }
        }
    }

    http://govnokod.ru/13631

    Собственно программа проверки

    vistefan 11 минут назад # 0
    С таким кодом вам тред новый надо было создавать.

    Создал, поливаем меня самодельным шоколадом

    kegdan, 21 Августа 2013

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

    +140

    1. 1
    while(index --> 1)

    iNsectus, 17 Августа 2013

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

    +140

    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
    public static Thread RunInNewThread(Action<string[]> method, string[] args, ThreadPriority priority)
    {
                Thread thread = new Thread(() => method(args));
                thread.Name = method.Method.Name;
                thread.SetApartmentState(ApartmentState.STA);
                thread.Priority = priority;
                thread.Start();
                return thread;
    }
    
    public static Thread RunInNewThread(Action<bool> method, bool args, ThreadPriority priority)
    {
                Thread thread = new Thread(() => method(args));
                thread.Name = method.Method.Name;
                thread.SetApartmentState(ApartmentState.STA);
                thread.Priority = priority;
                thread.Start();
                return thread;
    }
    
    public static Thread RunInNewThread(Action<DateTime> method, DateTime date, ThreadPriority priority)
    {
                Thread thread = new Thread(() => method(date));
                thread.Name = method.Method.Name;
                thread.SetApartmentState(ApartmentState.STA);
                thread.Priority = priority;
                thread.Start();
                return thread;
    }

    Шикарно

    taburetka, 16 Августа 2013

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

    +135

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    private readonly bool[] showDetails = new bool[20]
                                                      {
                                                          false, false, false, false, false, false, false, false, false, false,
                                                          false, false, false, false, false, false, false, false, false, false
                                                      };

    taburetka, 12 Августа 2013

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

    +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
    private string LineTabsCRLFToSpaces(string line)
            {
                string ret_line = "";
                if (line != null)
                {
                    //    throw new ArgumentNullException("line");
                    if (line.Length == 0) return string.Empty;  // Пустая входная строка
                    for (int i = 0; i < line.Length; i++)
                    {
                        char ch = line[i];
                        if (ch == '\t' || ch == '\r' || ch == '\n')
                            ret_line = ret_line + " ";
                        else
                            ret_line = ret_line + ch;
                    }
                }
                return ret_line;
            }

    - line.Replce()?
    - Не, не слышал!

    nolka4, 12 Августа 2013

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