string month = DateTime.Today.Month.ToString();
if (DateTime.Today.Month < 10)
{
    month = "0" + month;
}
string day = DateTime.Today.Day.ToString();
if (DateTime.Today.Day < 10)
{
    day = "0" + day;
}

string dateCorrect = String.Format("{0}.{1}.{2}", DateTime.Today.Year, month, day);

string dateDue = "";
if (transferFields.DueDate.SelectedDate.HasValue)
{
    var dateDuearr = transferFields.DueDate.Value.Split(' ')[0].Split('.');
    dateDue = dateDuearr[2] + '.' + dateDuearr[1] + '.' + dateDuearr[0];
}
else {
    dateDue = dateCorrect;
}

Real developers don't use built in parsing and formatting methods.

By You will be proud of our code!, 2017-12-12 09:53:08
if ((string)filtros[0] != "-1" && (string)filtros[0] != "0") 
    filtros[0] = (string)filtros[0] != "" ? filtros[0] : DBNull.Value;
    
else
    filtros[0] = DBNull.Value;  
By Anonymous, 2020-06-02 18:22:05
if (string.Compare(json["result"].ToString(), "OK", true) == 0)
{
    if (string.Compare(json["list"][0]["result"].ToString(), "OK", true) == 0)
        return null;
        
    //omitted
}
By J@k3R, 2022-08-09 08:51:55
    public static class DecimalHelpers
    {
        /// <summary>
        /// Format a decimal XX.XX to XX,XX%.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string FormatToStringPercentageValue(this decimal value)
        {
            return value.ToString().Replace(".", ",").FormatToPercentageValue();
        }
    }
    
    public static class StringHelpers
    {
        /// <summary>
        /// Add % at the end of the string.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string FormatToPercentageValue(this string value)
        {
            return string.Concat(value, "%");
        }
    }
By Anonymous, 2017-12-12 10:58:38
    if (model.env.Trim().ToUpper() == "Release")
    {
        retVal = false;
        if (!string.IsNullOrEmpty(model.Server_Core))
        {
            // Perform a trim in case user specified just whitespace...
            string tmpStr = model.Server_Core.Trim();
            if (!string.IsNullOrEmpty(tmpStr))
            {
                retVal = true;
            }
        }
    }
By Anonymous, 2019-02-25 17:12:31
public partial class Form1 : Form
   {
      public Form1()
      {
         InitializeComponent();
      }

      protected override void OnLoad(EventArgs e)
      {
         base.OnLoad(e);
         var token = new CancellationTokenSource().Token;
         Task.Factory.StartNew (() => {
            while (!token.IsCancellationRequested) {
               try {
                  if (/*Condition*/)
                     this.Invoke(new Action(() => label.Text = " =)"));
                  else
                     this.Invoke(new Action(() => label.Text = " =("));
                  Thread.Sleep(10);
               }
               catch (Exception) {
                  throw;
               }
               finally {
                  throw new Exception();
               }
            }
         }) ;
      }
   }

My collegue's way of using multithreading features (and exceptions handling) :)

By Loganjii, 2019-10-09 15:00:18
        /// <summary>
        /// Builds the suffixs for the request sequence number
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public static string GetSequenceNumber(int i)
        {
            string strCount = string.Empty;
            string increase = string.Empty;
            int count;
            strCount = i.ToString();
            count = strCount.Length;
            //Add 0 infront of the index to make a 4 digit number
            if (count < 5)
            {
                for (int j = 0; j < (4 - count); j++)
                {
                    increase = increase + "0";
                }
                strCount = increase + strCount;
            }
            return strCount;
        }
By Anonymous, 2021-04-21 16:01:46
public class NullableFloatToNullableDoubleConverter : ITypeConverter<float?, double?>
    {
        public double? Convert(float? source, double? destination, ResolutionContext context)
        {
            if (source == null)
            {
                return null;
            }

            var floatAsString = source.Value.ToString(CultureInfo.InvariantCulture);

            return double.Parse(floatAsString);
        }
    }
By Anonymous, 2019-01-31 12:05:33
        protected override void OnStartup(StartupEventArgs e)
        {
            Current.DispatcherUnhandledException += ApplicationUnhandledException;

            base.OnStartup(e);

#if (DEBUG)
            RunInDebugMode(e.Args);
#else
            RunInReleaseMode(e.Args);
#endif
        }

#endregion

        private static void RunInReleaseMode(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException;

            try
            {
                SplashScreen screen = new SplashScreen(@"Images\splashscreen.png");
                screen.Show(true, true);

                RunInDebugMode(args);
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }

        private static void RunInDebugMode(string[] args)
        {
            var bootstrapper = new Bootstrapper();
            bootstrapper.Run();
        }
By Anonymous, 2019-07-09 09:44:00
class ExampleClass {
    public void DoSomething()
    {
       if (this != null) {
           //omitted
       }
    }
    
    public void DoSomething2()
    {
       if (this != null) {
           //omitted
       }
    }
    
}

Explanation: This can't be null in C# virtual instance methods - I was so confused by the widespread use of this check that I asked this question at SO: https://stackoverflow.com/questions/31747718/can-this-be-null-in-c-sharp-virtual-methods-what-happens-with-the-rest-of-ins

By Michail Michailidis, 2017-12-13 14:54:58
StartCoroutine(Patrol());

public IEnumerator Patrol() {
    while(true) {
        dt.Walk();
        yield return new WaitForSeconds(reactionTime);
    }
}
By Mario, 2021-11-19 07:18:22
        public static bool ValidateEmailAddress(string emailAddress)
        {
            string pattern = "^((?>[a-zA-Z\\d!#$%&'*+\\-/=?^_`{|}~]+\x20*|\"((?=[\x01-\x7f])[^\"\\]|\\[\x01-\x7f])*\"\x20*)*(?<angle><))?((?!\\.)(?>\\.?[a-zA-Z\\d!#$%&'*+\\-/=?^_`{|}~]+)+|\"((?=[\x01-\x7f])[^\"\\]|\\[\x01-\x7f])*\")@(((?!-)[a-zA-Z\\d\\-]+(?<!-)\\.)+[a-zA-Z]{2,}|\\[(((?(?<!\\[)\\.)(25[0-5]|2[0-4]\\d|[01]?\\d?\\d)){4}|[a-zA-Z\\d\\-]*[a-zA-Z\\d]:((?=[\x01-\x7f])[^\\\\[\\]]|\\[\x01-\x7f])+)\\])(?(angle)>)$";

            if (!String.IsNullOrEmpty(emailAddress) && !(Regex.Match(emailAddress.Trim(), pattern, RegexOptions.IgnoreCase)).Success)
            {
                return false;
            }
            return true;
        }
By Anonymous, 2019-07-17 23:47:20
#411 C# +8
if (date.Training != null)
            {
                var training = date.Training;
                var status = new TrainingStatus();
                var refresher = new Training();

                if (training.Trainings != null)
                    refresher = training.Trainings;

                bool hasTakenRefresher = false;
                status.Value = date.Date.AddDays(
                    TrainingHelper.CalculateValidityDays(training.Validity ?? 0, training.ValidityType ?? 0));

                status.Name = training.TrainingName;
                status.ID = training.TrainingID;
                status.Category = training.CategoryTraining != null ? training.CategoryTraining.Name : "Other";
                status.IsTrained = _validityUtilsService.IsValid(training, date.Date);

                if (status.IsTrained)
                {
                    status.IsExpiring = _validityUtilsService.IsExpiring(training, date.Date,
                                            TrainingHelper.CalculateValidityDays(
                                                training.ExpirationWarningValidity ?? 0,
                                                training.ExpirationWarningValidityType ?? 0));
                }

                if (refresher.ID != 0)
                {
                    hasTakenRefresher = employee.Dates
                        .Count(x => x.Training != null
                            && x.TrainingID == refresher.ID) > 1;

                    if (hasTakenRefresher && (status.IsExpiring || !status.IsTrained))
                    {
                        status.IsExpiring = false;
                        var trainingWithNewValidity = new Training();

                        status.Value = date.Date.AddDays(
                            TrainingHelper.CalculateValidityDays(training.ValidityRefresher ?? 0,
                                training.ValidityRefresherType ?? 0));

                        trainingWithNewValidity.Validity = training.ValidityRefresher;
                        trainingWithNewValidity.ValidityType = training.ValidityRefresherType;
                        status.IsTrained = _validityUtilsService.IsValid(trainingWithNewValidity, date.Date);

                        if (status.IsTrained)
                        {
                            status.IsExpiring = _validityUtilsService.IsExpiring(trainingWithNewValidity, date.Date,
                                TrainingHelper.CalculateValidityDays(
                                    refresher.ExpirationWarningValidity ?? 0,
                                    refresher.ExpirationWarningValidityType ?? 0));
                        }
                    }
                }

                if (status.IsTrained && !status.IsExpiring)
                    status.Status = TrainingStatuses.Trained;
                else if (status.IsTrained && status.IsExpiring)
                    status.Status = TrainingStatuses.Expiring;
                else if (!status.IsTrained && !status.IsExpiring)
                    status.Status = TrainingStatuses.Expired;

                status.EmpID = employee.ID;

                return status;
            }

test

By NN, 2019-10-29 12:59:14
public class MetricsChecker
{
    protected const string AwaitingRecognitionCountMetricName = "AwaitingRecognitionCount";
    protected const string AwaitingExportCountMetricName = "AwaitingExportCount";
    protected const string NotYetDownloadedEventCountMetricName = "NotYetDownloadedEventCount";
    
    ...
    
    public virtual void PublishNotYetDownloadedEventCounts()
    {
        this.logger.Trace($"Starting to gather and publish {NotYetDownloadedEventCountMetricName}(s).");
        ...
    }
    
    ...
}
By Senior developer with 30 rear experience, 2019-12-13 16:22:28
/// <summary>
/// Returns true if any component of of Vector3 v is negative
/// </summary>
public static bool Ext_IsNegative(this Vector3 v)
{
    return v.x < 0f && v.y < 0f && v.z < 0f;
}

Either the description is wrong or the method in itself

By SwagridOfficial, 2017-12-13 13:00:34